problem inserting code into python function, works in console when typed out
so i'm trying to get something to work in a function and i don't know if it's a timing issue or what it might be.
in the console (python 3.6.4+, debian) -> Code:
>>> import socket (i've put the print() statements in to try and debug what is going on.) Code:
import socket Code:
'google.com' hopefully someone can help with this. contents of 'One_ip'(just a basic text file) -> 'google.com' 'debian.org' 'redhat.com' |
You don't need the quotes in the file ('debian.org')
'' just represents a string in python. Remove them from the One_ip file. To compare, when you typed it into the console, it got 'debian.org', however from the file it read it as ''debian.org'', a string that that quotes around it. It's also probably getting confused since there might be some newline there This fixes it -> .strip() Code:
import socket Code:
#!/usr/bin/env python3 Code:
#!/usr/bin/env python3 |
thanks Sefyir for your response.
so i tried the last one first, and it was only returning a 'generator object' which didn't work with the continuation of the script (not described). the first one works, didn't use a list, just the ip address is needed for what i want to do. thanks for pointing out the .strip() and the need to not need the quotes, when reading my 'python pocket reference' i didn't see that it would return the \n at the end. take care. em |
All times are GMT -5. The time now is 06:22 AM. |