Jan-18-2017, 05:22 PM
Pages: 1 2
Jan-18-2017, 05:24 PM
What do you mean exactly?
s = "Printed line :)" print(s)?
Jan-18-2017, 05:30 PM
I am using a for loop to print a txt which contains emails
I want all those printed emails to be looped as well and define x.
x = printed email
Example:
[email protected] #1 email
[email protected] #2 email
.
.
.
I can t express myself very good.
I want all those printed emails to be looped as well and define x.
x = printed email
Example:
[email protected] #1 email
[email protected] #2 email
.
.
.
I can t express myself very good.
Jan-18-2017, 05:44 PM
Use a dictionary,you loop over with enumerate(set start at 1).
data ='''\ [email protected] [email protected]'''' >>> d = {} >>> for index,email in enumerate(data.split('\n'), 1): ... d['email{}'.format(index)] = email ... >>> d {'email1': '[email protected]', 'email2': '[email protected]'} >>> d['email2'] '[email protected]'
Jan-18-2017, 05:46 PM
A short representation of the file and the code snippet with what you tried so far will clear the picture.
You want 'x' to contain one email per loop or you want to add any printed email to 'x' as a list?
You want 'x' to contain one email per loop or you want to add any printed email to 'x' as a list?
Jan-18-2017, 05:52 PM
I want "x" to contain 1 email per loop. :>
Jan-18-2017, 06:45 PM
How does the file is formatted?
Jan-18-2017, 06:56 PM
It's a txt. like
[email protected]
[email protected]
.
.
.
etc
To be more precise , i need something like : first line to be used in a send email script, run it and go at sencond line . etc. looping like that until the emails from txt file it ends. Sorry for bad english.
[email protected]
[email protected]
.
.
.
etc
To be more precise , i need something like : first line to be used in a send email script, run it and go at sencond line . etc. looping like that until the emails from txt file it ends. Sorry for bad english.
Jan-18-2017, 07:17 PM
with open('emails.txt', 'r') as inputfile: while inputfile: email = inputfile.readline() print(email) # do something else
Jan-18-2017, 07:26 PM
Hmm or.
What we have at end is just the last line stored in email variable.
Maybe easier to see if i do the same in my code:
with open('emails.txt', 'r') as f_obj: for line in f_obj print(line)so here get email variable overwritten in every loop iteration
email = inputfile.readline()
What we have at end is just the last line stored in email variable.
Maybe easier to see if i do the same in my code:
with open('emails.txt', 'r') as f_obj: for line in f_obj: email = line print(email)
Pages: 1 2