Jan-18-2017, 05:22 PM
How can i use a printed line as a varible?
I mean "a printed line (adsialdh) = x"
I mean "a printed line (adsialdh) = x"
Print line
|
Jan-18-2017, 05:22 PM
How can i use a printed line as a varible?
I mean "a printed line (adsialdh) = x"
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.
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]'
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?
Jan-18-2017, 05:52 PM
I want "x" to contain 1 email per loop. :>
How does the file is formatted?
Jan-18-2017, 06:56 PM
(This post was last modified: Jan-18-2017, 06:59 PM by eftemie0000.)
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. with open('emails.txt', 'r') as inputfile: while inputfile: email = inputfile.readline() print(email) # do something else
Hmm or.
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) |
|