Feb-19-2019, 06:08 PM
hello, I have a code, and it is simply, but it need to be improved. My code get all value in the line. They assigned the value to the number of the line. After that, they write in the file, line per line, the value, and one line write the value and add 1 to the value.
This is my code, the numbers is in french, is 1 to 40
Thank you for you time
This is my code, the numbers is in french, is 1 to 40
import paramiko import os from paramiko import sftp_handle quaranteetun=41 zero=0 # number 0 to 40 in french un=0 deux=0 trois=0 quatre=0 cinq=0 six=0 sept=0 huit=0 neuf=0 dix=0 onze=0 douze=0 treize=0 quatorze=0 quinze=0 seize=0 dixsept=0 dixhuit=0 dixneuf=0 vingt=0 vingtetun=0 vingtdeux=0 vingttrois=0 vingtquatre=0 vingtcinq=0 vingtsix=0 vingtsept=0 vingthuit=0 vingtneuf=0 trente=0 trenteetun=0 trentedeux=0 trentetrois=0 trentequatre=0 trentecinq=0 trentesix=0 trentesept=0 trentehuit=0 trenteneuf=0 quarante=0 # end of the number 0 to 40 in french x="un" i=1 b=0 variable=41 file="/home/pi/SiteCyberdependance/donne/donne.txt" self=paramiko.SFTPFile.write read = paramiko.SFTPFile.read ssh_client = paramiko.SSHClient open = paramiko.SFTPClient.open write=paramiko.SFTPFile._write host = "41.41.41.41" port = 22 transport = paramiko.Transport((host, port)) password = "41" username = "pi" transport.connect(username = username, password = password) sftp = paramiko.SFTPClient.from_transport(transport) SFTPFile=paramiko.SFTPFile.write f = sftp.open("/home/pi/SiteCyberdependance/donne/donne.txt", "r+") with sftp.open("/home/pi/SiteCyberdependance/donne/donne.txt") as f: for line in f: line=int(line) b=line print(line, end='') while x==quarante: #quarante correspond to 40, x is equal to the line number, quarante stock the value of the line 40. each 40 line have a value stocked. quarante=b #var quarante(40) correspond to b, b correspond to the line 40, this for stock the number in the line while x==trenteneuf: #same thing than above, but is 39 trenteneuf=b x=quarante #this is for switch the line we get the value while x==trentehuit:#38 trentehuit=b x=trenteneuf while x==trentesept:#37 trentesept=b x=trentehuit while x==trentesix:#36 trentesix=b x=trentesept while x==trentecinq:#35 trentecinq=b x=trentesix while x==trentequatre:#34 trentequatre=b x=trentecinq while x==trentetrois:#33 trentetrois=b x=trentequatre while x==trentedeux:#32 trentedeux=b x=trentetrois while x==trenteetun:#31 trenteetun=b x=trentedeux while x==trente:#30 trente=b x=trenteetun while x==vingtneuf:#29 vingtneuf=b x=trente while x==vingthuit:#28 vingthuit=b x=vingtneuf while x==vingtsept:#27 vingtsept=b x=vingthuit while x==vingtsix:#26 vingtsix=b x=vingtsept while x==vingtcinq:#25 vingtcinq=b x=vingtsix while x==vingtquatre:#24 vingtquatre=b x=vingtcinq while x==vingttrois:#23 vingttrois=b x=vingtquatre while x==vingtdeux:#22 vingtdeux=b x=vingttrois while x==vingtetun:#21 vingtetun=b x=vingtdeux while x==vingt:#20 vingt=b x=vingtetun while x==dixneuf:#19 dixneuf=b x=vingt while x==dixhuit:#18 dixhuit=b x=dixneuf while x==dixsept:#17 dixsept=b x=dixhuit while x==seize:#16 seize=b x=dixsept while x==quinze:#15 quinze=b x=seize while x==quatorze:#14 quatorze=b x=quinze while x==treize:#13 treize=b x=quatorze while x==douze:#12 douze=b x=treize while x==onze:#11 onze=b x=douze while x==dix:#10 dix=b x=onze while b==neuf:#9 neuf=b x=dix while x==huit:#8 huit=b x=neuf while x==sept:#7 sept=b x=huit while x==six:#6 six=b x=sept while x==cinq:#5 cinq=b x=six while x==quatre:#4 quatre=b x=cinq while x==trois:#3 trois=b x=quatre while x==deux:#2 deux=b x=trois while x==un:#1 un=b un+1 x=deux # here we write the stocked value, b= value stock in the line and write it, I have tried to put [b]""[/b] around the number, because we want the string "trenteneuf" not the value of trenteneuf f = sftp.open("/home/pi/SiteCyberdependance/donne/donne.txt", "w") x="zero" with sftp.open("/home/pi/SiteCyberdependance/donne/donne.txt") as f: for x in range(1, 40): while x=="trenteneuf": b=quarante x=("quarante") while x=="trentehuit": b=trenteneuf x=("trenteneuf") while x=="trentesept": b=trentehuit x=("trentehuit") while x=="trentesix": b=trentesept x="trentesept" while x=="trentecinq": b=trentesix x="trentesix" while x=="trentequatre": b=trentecinq x="trentecinq" while x=="trentetrois": b=trentequatre x="trentequatre" while x=="trentedeux": x="trentetrois" while x=="trenteetun": b=trentedeux x="trentedeux" while x=="trente": b=trenteetun x="trenteetun" while x=="vingtneuf": b=trente x="trente" while x=="vingthuit": b=vingtneuf x="vingtneuf" while x=="vingtsept": b=vingthuit x="vingthuit" while x=="vingtsix": b=vingtsept x="vingtsept" while x=="vingtcinq": b=vingtsix x="vingtsix" while x=="vingtquatre": b=vingtcinq x="vingtcinq" while x=="vingttrois": b=vingtquatre x="vingtquatre" while x=="vingtdeux": b=vingttrois x="vingttrois" while x=="vingtetun": b=vingtdeux x="vingtdeux" while x=="vingt": b=vingtetun x="vingtetun" while x=="dixneuf": b=vingt x="vingt" while x=="dixhuit": b=dixneuf x="dixneuf" while x=="dixsept": dixsept=b x="dixhuit" while x=="seize": b=dixsept x="dixsept" while x=="quinze": b=seize x="seize" while x=="quatorze": b=quinze x="quinze" while x=="treize": b=quartoze x="quatorze" while x=="douze": b=treize x="treize" while x=="onze": b=douze x="douze" while x=="dix": b=onze x="onze" while b=="neuf": b=dix x=str("dix") while x=="huit": b=neuf x=str("neuf") while x=="sept": b=huit x=str("huit") while x=="six": b=sept x=str("sept") while x=="cinq": b=six x=str("six") while x=="quatre": b=cinq x=str("cinq") while x=="trois": b=quatre x=str("quatre") while x=="deux": b=trois x=str("trois") while x=="un": b=deux x=str("deux") while x=="zero": x="un" b=str(int(b)) sftp=paramiko.SFTPFile.write write(self, data=b)I know I can make it with a list, I have tried, but I got error all the time.
Thank you for you time