Re: [Tutor] crontab or python mistake
> IOError: [Errno 2] No such file or directory: ' emmssg.txt' > > the emmssg.txt file is in the /root/script directory so i > don't know why it cant find it. The file may be there but crontab isn't. It runs the program as root and root's home directory is /. For this kind of thing you need to either pass in the data directory as an argument or wrap the python script in a shell script that sets an environment variable to where your data is and then runs the pyhon script. Within the script use getenv to find the path. Or just hard code the path... Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] partial string matching in list comprehension?
doug shawhan wrote: > I have a series of lists to compare with a list of exclusionary terms. > > > > junkList =["interchange", "ifferen", "thru"] > > The comparison lists have one or more elements, which may or may not > contain the junkList elements somewhere within: > > l = ["My skull hurts", "Drive the thruway", "Interchangability is not my > forte"] > > ... output would be > > ["My skull hurts"] > > I have used list comprehension to match complete elements, how can I do > a partial match? > > def removeJunk(reply, junkList): > return [x for x in reply if x not in junkList] > > It would be so much prettier than searching through each list element > for each term - I tend to get lost in a maze of twisty corridors, all alike. > > Thanks! > > Dunno if the performance of this solution is good and if it is more readable then RegExps, but here is LC: [x for x in l if not [j for j in junkList if x.lower().find(j) > -1]] >>> l = ["My skull hurts", "Drive the thruway", "Interchangability is not my forte"] >>> junkList =["interchange", "ifferen", "thru"] >>> [x for x in l if not [j for j in junkList if x.lower().find(j) > -1]] ['My skull hurts', 'Interchangability is not my forte'] ^ Is there an "e" missing? Because I don't like RegExps! ;-) HTH, Wolfram ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] partial string matching in list comprehension?
Wolfram Kraus wrote: > doug shawhan wrote: >> I have a series of lists to compare with a list of exclusionary terms. >> >> >> >> junkList =["interchange", "ifferen", "thru"] >> >> The comparison lists have one or more elements, which may or may not >> contain the junkList elements somewhere within: >> >> l = ["My skull hurts", "Drive the thruway", "Interchangability is not my >> forte"] >> >> ... output would be >> >> ["My skull hurts"] >> >> I have used list comprehension to match complete elements, how can I do >> a partial match? >> >> def removeJunk(reply, junkList): >> return [x for x in reply if x not in junkList] >> >> It would be so much prettier than searching through each list element >> for each term - I tend to get lost in a maze of twisty corridors, all alike. >> >> Thanks! >> >> > Dunno if the performance of this solution is good and if it is more > readable then RegExps, but here is LC: > [x for x in l if not [j for j in junkList if x.lower().find(j) > -1]] A little cleaner is [ j for j in junkList if j not in x.lower() ] This will compute x.lower() for each element of junkList... Kent > > >>> l = ["My skull hurts", "Drive the thruway", "Interchangability is > not my forte"] > >>> junkList =["interchange", "ifferen", "thru"] > >>> [x for x in l if not [j for j in junkList if x.lower().find(j) > -1]] > ['My skull hurts', 'Interchangability is not my forte'] >^ Is there an "e" missing? > > Because I don't like RegExps! ;-) > > HTH, > Wolfram > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] partial string matching in list comprehension?
Kent Johnson wrote: > Wolfram Kraus wrote: > >>doug shawhan wrote: >> >>>I have a series of lists to compare with a list of exclusionary terms. >>> >>> >>> >>>junkList =["interchange", "ifferen", "thru"] >>> >>>The comparison lists have one or more elements, which may or may not >>>contain the junkList elements somewhere within: >>> >>>l = ["My skull hurts", "Drive the thruway", "Interchangability is not my >>>forte"] >>> >>>... output would be >>> >>>["My skull hurts"] >>> >>>I have used list comprehension to match complete elements, how can I do >>>a partial match? >>> >>>def removeJunk(reply, junkList): >>>return [x for x in reply if x not in junkList] >>> >>>It would be so much prettier than searching through each list element >>>for each term - I tend to get lost in a maze of twisty corridors, all alike. >>> >>>Thanks! >>> >>> >> >>Dunno if the performance of this solution is good and if it is more >>readable then RegExps, but here is LC: >>[x for x in l if not [j for j in junkList if x.lower().find(j) > -1]] > > A little cleaner is > [ j for j in junkList if j not in x.lower() ] > > This will compute x.lower() for each element of junkList... > > Kent > Ahh, yes. Stupid old string methods :-S But you are not quite correct, it has to be [x for x in l if not [j for j in junkList if j in x.lower() ]] See the "not"-ed parts ;-) Wolfram ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] crontab or python mistake
Am Freitag, den 26.05.2006, 08:32 +0100 schrieb Alan Gauld: > > > IOError: [Errno 2] No such file or directory: ' emmssg.txt' > > > > > the emmssg.txt file is in the /root/script directory so i > > don't know why it cant find it. > > The file may be there but crontab isn't. It runs the program > as root and root's home directory is /. > > For this kind of thing you need to either pass in the > data directory as an argument or wrap the python script > in a shell script that sets an environment variable to > where your data is and then runs the pyhon script. > Within the script use getenv to find the path. Well, he can do the following stuff: -) wrap it in a shell script that changes to current directory to the expected one. -) do that inside the python script. -) make the file path absolute somehow: *) code it as a constant int the script. *) make it an argument (see sys.argv or module optparse) *) make it an argument via the environment (os.environ, not getenv) Andreas > > Or just hard code the path... > > Alan G > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unable to import xxx.pyd
Well, xxx.pyd -> dynamic binary python module on Windows. security value "755" suggests that you are trying to install it on a Linux/Unix host. Sorry, but dynamic binary modules on Linux end in ".so" (every Unix treats that a little bit different, HPUX e.g. uses .sl, etc.) And no, you cannot just copy a .pyd file from a Windows distribution to a Linux host and expect it to work. (Actually .pyd files are sometimes incompatible between differently compiled Python versions on Win32) Andreas Am Donnerstag, den 25.05.2006, 14:20 -0500 schrieb URBAN LANDREMAN: > I'm debugging a program where I'm trying to import a file named xxx.pyd. > > I test the logic interactively with IDLE and see that it makes a difference > on which directory the file xxx.pyd is located. That is, I can get it to > work when xxx.pyd is on the path. > > However, when I run the program in batch > #!/usr/local/bin/python > import cgitb; cgitb.enable() > print "Content-type: text/html" > print > print "" > import sys > print sys.path > import xxx > > I get the error message: No module named xxx, even though I know that the > file xxx.pyd is on the path. If I put a file xxx.py in the same folder, the > system finds that file. > > The file xxx.pyd has security numeric value 755, so the system should be > able to find it. > > I'm baffled. > > Any suggestions of what my be causing the system to not find xxx.pyd? > > Thanks. > > > Urban Landreman > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to import a module which was not in the current working directory?
Hi, How to import a module which was not in the current working directory? Thanks, Linda ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to import a module which was not in the current working directory?
linda.s wrote: > Hi, > How to import a module which was not in the current working directory? This was just discussed on the list: http://mail.python.org/pipermail/tutor/2006-May/047053.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to import a module which was not in the current working directory?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Linda, You can append your path to include the location of the module. An example of this would be: sys.path.append(r'\\share\somedirectory') linda.s wrote: > Hi, > How to import a module which was not in the current working directory? > Thanks, > Linda > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (MingW32) iD8DBQFEdxZUDvn/4H0LjDwRAovqAJ99tie7ZVJiFdHF/wnqxYGujBmhuQCdFWEw fFa4k3xTnxwr/nPmuG8PW1Q= =IVFd -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] seg fault from qt
Hi, For some reason I have lost qt. I'd like to know what I have to re-install to get python qt lib for SUSE 10.0. When I use YAST I see nothing like python-qt Right now I do import qt I get seg fault John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to import a module which was not in the current working directory?
Hi Linda, Let say you have a tool named convert.py and other module (processing.py) in modules folder. In modules folder create an empty file named __init__.py In convert.py do: from modules import processing.py It would work. da linda.s wrote: > Hi, > How to import a module which was not in the current working directory? > Thanks, > Linda > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Download file from the web and store it locally.
> You need to step back a bit and get a better understanding of > variables > and functions and how to use them. You are trying to run before you > can walk. >: > You need to sit down and work through which variables you need > and which functions of urllib you need. > > I suspect you only need to use urllib.urlretrieve() and your total > code should only be 3 or 4 lines long. matata, i agree with alan here. it does not even look like your program should even get up to the point where you think that it should be working up to. i suspect plenty of NameError exceptions. what you should do is to simplify first: get rid of most variables and definitely that exception handler (try-except). write down the steps (in pseudocode) as to what you want to do, what variables you want to use, etc. after you get things working, you can dress up your code with the extras. after that, you should be able to piece together which variables you really need and be able to construct the proper Python code from there. as alan has suggested, what i think you want to do, involves using urllib.urlretrieve() and should only take a 3-5 lines of code. good luck! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor