[Tutor] File locking: cross platform?
Hello, What is the correct way to implement cross-platform "flock like" file locking? Specifically, how would i acquire "exclusive read-write" and "shared read-only" locks for a CGI script that I expect to run on both Windows and Linux servers. Thank you, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] building Python 2.6?
Hello, I am trying to build python 2.6 on a machine (web server) that I do not have root access to. (has 2.4 installed) Python 2.5 builds fine, but I am getting an error when I run "make" for 2.6.1 Here is the command line I am using: ../configure -prefix=/home/username/local-python/ --enable-unicode=ucs4 (I don't know what the ucs4 thing is, but all the HOWTOs I saw say to use it. ) Here is what the local python reports itself as: Python 2.4.3 (#1, Jul 29 2007, 14:09:31) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Here is the error after I run "make": [SNIP] /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: error: syntax error before '*' token /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: warning: function declaration isn't a prototype /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In function `CFuncPtr_nonzero': /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: error: `self' undeclared (first use in this function) Failed to find the necessary bits to build these modules: _tkinter bsddb185 sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _ctypes running build_script ~~~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] building Python 2.6?
> > Python 2.5 builds fine, but I am getting an error when I run "make" for > > 2.6.1 > > > > Here is the command line I am using: > > ../configure -prefix=/home/username/local-python/ --enable-unicode=ucs4 > > > > (I don't know what the ucs4 thing is, but all the HOWTOs I saw say to use > > it. > ) > > UCS (universal character set) is the name of the ISO norm that is +/- > equivalent > to unicode. ucs-4 is an encoding equivalent to utf-16, if I remenber well. > Is this something I need? Do it hurt to use it? > > > > Here is what the local python reports itself as: > > > > > > Python 2.4.3 (#1, Jul 29 2007, 14:09:31) > > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 > > > > > > Here is the error after I run "make": > > > > [SNIP] > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3941: > > error: > syntax error before '*' token > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3942: > > warning: > function declaration isn't a prototype > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c: In > > function > `CFuncPtr_nonzero': > > /home/username/local-src/Python-2.6.1/Modules/_ctypes/_ctypes.c:3943: > > error: > `self' undeclared (first use in this function) > > > > Failed to find the necessary bits to build these modules: > > _tkinter bsddb185 sunaudiodev > > To find the necessary bits, look in setup.py in detect_modules() for the > module's name. > > > > > > Failed to build these modules: > > _ctypes > > > > running build_script > > ~~~ > > Saw the same kind of error report for buiding ctypes, precisely, on another > list. It seemed that this module's buiding is platform dependant. Well > informed > people said that it's not needed anyway (it allows using native C value types > in > python code). > Don't know more myself. > HmmDo I need ctypes to use TurboGears/Pylons/etc? Is the problem fixable? If I chose to not use ctypes, how do I correctly build 2.6 without it? Thank you :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] regex: not start with FOO
Hello, I'd like to match any line that does not start with FOO. (Using just a reg-ex rule) 1) What is the effective difference between: (?!^FOO).* ^(?!FOO).* 2) Is there a better way to do this? Thanks, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regex: not start with FOO
> > I'd like to match any line that does not start with FOO. (Using just a > > reg-ex > rule) > > > > 1) What is the effective difference between: > > > > (?!^FOO).* > > > > ^(?!FOO).* > > > > 2) Is there a better way to do this? > > > > myline = 'FOO things in line' > > >>> myline.startswith('FOO') > True Right. However, I am trying to just do this in a general "does this match" regex environment. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regex: not start with FOO
> > I'd like to match any line that does not start with FOO. (Using just a > > reg-ex > rule) > > > > 1) What is the effective difference between: > > > > (?!^FOO).* > > > > ^(?!FOO).* > > One difference is that the first will match starting anywhere in a > string, while the second will match only at the start. For this exact > example I don't think it matters but if you replace .* with something > else you can see a difference. For example: > In [52]: re.findall('(?!^FOO) in', 'in in in') > Out[52]: [' in', ' in'] > > In [53]: re.findall('^(?!FOO) in', 'in in in') > Out[53]: [] > > I think I would use the second form, it seems to more directly express > what you mean. > Hmm... In [30]: re.findall('(?!FOO)in', 'in FOOin in') Out[30]: ['in', 'in', 'in'] OK, now I am confused... . why am I getting 3 results? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regex: not start with FOO
> > I'd like to match any line that does not start with FOO. (Using just a > > reg-ex > rule) > > > > 1) What is the effective difference between: > > > > (?!^FOO).* > > > > ^(?!FOO).* > > One difference is that the first will match starting anywhere in a > string, while the second will match only at the start. For this exact > example I don't think it matters but if you replace .* with something > else you can see a difference. For example: > In [52]: re.findall('(?!^FOO) in', 'in in in') > Out[52]: [' in', ' in'] > > In [53]: re.findall('^(?!FOO) in', 'in in in') > Out[53]: [] > > I think I would use the second form, it seems to more directly express > what you mean. > Thank you... that clarifies things greatly. Now, to change the example slightly: In [3]: re.findall('^(?!FOO)in', 'in in in') Out[3]: ['in'] In [4]: re.findall('(?!^FOO)in', 'in in in') Out[4]: ['in', 'in', 'in'] In [5]: re.findall('(?!FOO)in', 'in in in') Out[5]: ['in', 'in', 'in'] In [6]: re.findall('(?!FOO$)in', 'in in in') Out[6]: ['in', 'in', 'in'] In [7]: re.findall('(?!^FOO$)in', 'in in in') Out[7]: ['in', 'in', 'in'] What is the effective difference between numbers 4 thru 7? That is, what effect does a string position anchor have within the sub expression? Thank you, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] calling other process?
Hello, I've been reading the Python docs on how to call a 2nd program and getting it's output, and would up here: http://docs.python.org/library/subprocess.html Is: from subprocess import Popen output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0] Really the replacement for: output = `mycmd myarg` Is there a less verbose, yet still official supported, way to capture STDOUT from a different program? Thank you, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling other process?
> > Is: > > > > from subprocess import Popen > > output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0] > > > > Really the replacement for: > > > > output = `mycmd myarg` > > Yes, because it works more consistently and reliably across > operating systems for one reason. Its also much more powerful > and flexible. > [SNIP] > Remember that in the zen of Python : > a) There should be one-- and preferably only one --obvious way to do > it. > b) explicit is better than implicit. > > http://www.python.org/dev/peps/pep-0020/ > Thanks for clearing that up. Not to discount the Python Zen, but me thinks there could be a little more "Make easy things easy, and hard things possible"in this aspect of Python . :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling other process?
> > I sympatjise but to be honest I never use the backtick trick except at > the >>> prompt as a quick and dirty hack. It ranks alongside the _ variable > in my book as an interactive utility but it's too easy to miss or misread to > use > > in real code. > > But even popen is easier, I agree, and I am still weaning myself away from > popen to Popen... But I can see the reasoning behind the move. > > Of course if you do a lot of that you could always define a function > that supplies default values for everything but the command. > True enough. On a slight different note, what would be the correct subprocess call if I want to pipe an email message to "/usr/sbin/sendmail -t -i"? (SMTP, thus smtplib, is not liked very much by the sysadmin) Thanks again, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor