Python Forum
write in a distant file, code improvement with a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
write in a distant file, code improvement with a list
#1
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
import paramiko
import os
from paramiko import sftp_handle
quaranteetun=41
zero=0
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
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=b
        while x==trenteneuf:
            trenteneuf=b
            x=quarante
        while x==trentehuit:
            trentehuit=b
            x=trenteneuf
        while x==trentesept:
            trentesept=b
            x="trentehuit"
        while x==trentesix:
            trentesix=b
            x="trentesept"
        while x==trentecinq:
            trentecinq=b
            x=trentesix
        while x==trentequatre:
            trentequatre=b
            x=trentecinq
        while x==trentetrois:
            trentetrois=b
            x=trentequatre
        while x==trentedeux:
            trentedeux=b
            x=trentetrois
        while x==trenteetun:
            trenteetun=b
            x=trentedeux"
        while x==trente:
            trente=b
            x=trenteetun
        while x==vingtneuf:
            vingtneuf=b
            x=trente
        while x==vingthuit:
            vingthuit=b
            x=vingtneuf
        while x==vingtsept:
            vingtsept=b
            x=vingthuit
        while x==vingtsix:
            vingtsix=b
            x=vingtsept
        while x==vingtcinq:
            vingtcinq=b
            x=vingtsix
        while x==vingtquatre:
            vingtquatre=b
            x=vingtcinq
        while x==vingttrois:
            vingttrois=b
            x=vingtquatre
        while x==vingtdeux:
            vingtdeux=b
            x=vingttrois
        while x==vingtetun:
            vingtetun=b
            x=vingtdeux
        while x==vingt:
            vingt=b
            x=vingtetun
        while x==dixneuf:
            dixneuf=b
            x=vingt
        while x==dixhuit:
            dixhuit=b
            x=dixneuf
        while x==dixsept:
            dixsept=b
            x=dixhuit
        while x==seize:
            seize=b
            x=dixsept
        while x==quinze:
            quinze=b
            x=seize
        while x==quatorze:
            quatorze=b
            x=quinze
        while x==treize:
            treize=b
            x=quatorze
        while x==douze:
            douze=b
            x=treize
        while x==onze:
            onze=b
            x=douze
        while x==dix:
            dix=b
            x=onze
        while b==neuf:
            neuf=b
            x=dix
        while x==huit:
            huit=b
            x=neuf
        while x==sept:
            sept=b
            x=huit
        while x==six:
            six=b
            x=sept
        while x==cinq:
            cinq=b
            x=six
        while x==quatre:
            quatre=b
            x=cinq
        while x==trois:
            trois=b
            x=quatre
        while x==deux:
            deux=b
            x=trois
        while x==un:
            un=b
            x=deux
        while x==zero:
            un=b
            un+1
            x=un



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
Reply


Messages In This Thread
code improvement - by lateublegende - Feb-19-2019, 04:02 PM
RE: code improvement - by ichabod801 - Feb-19-2019, 07:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Any suggestions for improvement?(my first python code) PyAlex 9 6,203 Sep-08-2018, 06:45 PM
Last Post: PyAlex

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020