[Tutor] More IDE's (was: Boa-Constructor)
This thread made me wonder: Is anyone out there using Eclipse and PyDev? (I started using Eclipse when I was toying around in Jython, and know others that are using it for C/C++, but I am curious if others have tried out PyDev and what they think). ~Denise ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Download an image of a site?
Kent Johnson wrote: > I don't think the object returned from urllib2.urlopen() has save() and get() > > methods. According to the docs urlopen() "returns a file-like object > with two > additional methods: > >* geturl() -- return the URL of the resource retrieved >* info() -- return the meta-information of the page, as a dictionary-like > object" > > So you should treat data.f like an open file - use read() to get the contents > into a > variable. Then open a real (disk) file for writing and write it out. > This section of > the Python tutorial has a quick intro: > http://docs.python.org/tut/node9.html#SECTION00920 > > Kent Thanks. I will check this out and let you know if I can get it to work. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Another regular expression question
Bernard Lebel wrote: > Hello, yet another regular expression question :-) > > So I have this xml file that I'm trying to find a specific tag in. For > this I'm using a regular expression. Right now, the tag I'm trying to > find looks like this: > > > > So I'm using a regular expression to find: > sceneobject > type="CameraRoot" > > > My code looks like this: > > > import os, re > > > def searchTag( sPattern, sFile ): > > """ > Scans a xml file to try to find a line that matches search criterias. > > ARGUMENTS: > sPattern (string): regular expression pattern string > sFile (string): full file path to scan > > RETURN VALUE: text line (string) or None > """ > > oRe = re.compile( sPattern ) > > if os.path.exists( sFile ) == False: return None No need to compare to False, you can just say if not os.path.exists( sFile ): return None > else: > oFile = file( sFile, 'r' ) > > for sLine in oFile.xreadlines(): # read text for sLine in oFile: is more idiomatic and avoids reading the whole file at once. > oMatch = oRe.search( sLine ) # attempt a search > if oMatch != None: # check if search returned success > oFile.close() > return sLine > > # Scan has yield no result, return None > oFile.close() > return None > > > sLine = searchTag( r'(sceneobject)(type="CameraRoot")', sFile ) > > > The thing is that I suspect my regular expression pattern to be > incorrect because I always get None, but am at a loss here. Any advice > would be welcomed. You need something in the regex to match the part between 'sceneobject' and 'type="CameraRoot"'. The regex you are using expects them to be adjacent. Try sLine = searchTag( r'(sceneobject).*?(type="CameraRoot")', sFile ) which means, match anything between the two strings, but the smallest amount possible (non-greedy). It's also possible that the tag you are looking for spans multiple lines. In this case you should look at an XML parsing library. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Another regular expression question
Hello, yet another regular expression question :-) So I have this xml file that I'm trying to find a specific tag in. For this I'm using a regular expression. Right now, the tag I'm trying to find looks like this: So I'm using a regular expression to find: sceneobject type="CameraRoot" My code looks like this: import os, re def searchTag( sPattern, sFile ): """ Scans a xml file to try to find a line that matches search criterias. ARGUMENTS: sPattern (string): regular expression pattern string sFile (string): full file path to scan RETURN VALUE: text line (string) or None """ oRe = re.compile( sPattern ) if os.path.exists( sFile ) == False: return None else: oFile = file( sFile, 'r' ) for sLine in oFile.xreadlines(): # read text oMatch = oRe.search( sLine ) # attempt a search if oMatch != None: # check if search returned success oFile.close() return sLine # Scan has yield no result, return None oFile.close() return None sLine = searchTag( r'(sceneobject)(type="CameraRoot")', sFile ) The thing is that I suspect my regular expression pattern to be incorrect because I always get None, but am at a loss here. Any advice would be welcomed. Thanks Bernard ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python as operating system?
> Python is theoretically capable of being used to write an OS, but that > is an exercise that is probably left to theory. There are a lot of good > OS'es out there that would undoubtedly perform much better than a > PythonOS ever could. That doesn't mean it wouldn't be cool, though. :-) I haven't looked at this too closely, but: http://sourceforge.net/projects/cleese appears to show that the theory can be applied, even if it isn't practical. *grin* Not sure if this project is still active, though. [Off-topic from Python: there are several other mature systems written in high level languages. These systems could be considered as OS's in their own right. The Smalltalk folks, for example, have had this for a long time; Squeak could be considered a high-level operating system: http://www.squeak.org/ MrEd/DrScheme is another compelling example of a system that could be considered a high-level operating system, given the environment that they expose. The paper: http://www.ccs.neu.edu/scheme/pubs/icfp99-ffkf.pdf talks about this in more detail.] Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mamelauncher (fwd)
On Tue, 13 Sep 2005, Max Russell wrote: > There actually seems to be a bit of a problem in the interaction with > the system when it launches mame. > > If I run this: > > import os > > def run_mame_selection(selection): > os.system("C:\\mame096b\\mame.exe"+ selection) > > #main > selection = " tnzs" > run_mame_selection(selection) > raw_input() > > mame reports files missing, but I can launch the game manually- I > suspect that this is some sort of error that occurs normally but is > bypassed on launch and that my one-shot attempt to launch the thing > cannot handle. Hi Max, H... that'll be something you'll want to check then. At least we can see that there might be some problems there. Do you know if the current working directory matters to MAME, or if it's looking for any particular environmental variables? Perhaps you might want to post those errors on a MAME support group, to see if other people know how to fix things properly. By the way, I notice that you're accounting above for the possible bug of having the selection text smushed right into the front of the selection text by manually prepending a space: ## > def run_mame_selection(selection): > os.system("C:\\mame096b\\mame.exe"+ selection) > selection = " tnzs" ## That was the bug that I thought was really causing problems, since's it wasn't clear at all that the code was handling the possible issue of the wordsrunningtogether. But you may want to modify run_mame_selection so that it does the prepending for you: ## def run_mame_selection(selection): os.system("C:\\mame096b\\mame.exe %s" % selection) ## That way, there's no possiblity of making that kind of mistake. Unforunately, this isn't robust because if 'selection' itself contains weird characters like quotes or spaces, that'll probably cause problems. Instead, we can pass a real list of command line arguments and avoid worrying about shell escape and quotation issues. For example, instead of: ## >>> f = os.popen("ls -l /etc/passwd") >>> f.read() '-rw-r--r-- 1 root root 1957 Jul 12 17:25 /etc/passwd\n' ## it is preferable to do: ## >>> child_stdin, child_stdout = os.popen2(['ls', '-l', '/etc/passwd']) >>> child_stdout.read() '-rw-r--r-- 1 root root 1957 Jul 12 17:25 /etc/passwd\n' ## If the filename here had spaces in it, then the first example with os.popen() will probably break. But the second with os.popen2 and the list of explicit arguments should fare better. > I think I need to have a wee look at subprocess! Unfortunately, you'll probably run into similar problems with 'subprocess'. I think the problem here is your MAME setup: it might be expecting something in your environment that isn't there, like the correct current working directory, or something else. I don't know too much about MAME, so I can't say in definite terms what's going on with the MAME error messages. Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
* jon freddy <[EMAIL PROTECTED]> [2005-09-13 13:37]: > I am new to Python, about 1 day. And I downloaded from > python.org Pythong2.4, it has the command line and > junk. But what actuall program compiles the source of > python into a program? Any of the programs included in > the package? And also, is Python capable of writing an > OS? Hi, Jon. Python is an interpreted language, your script is "compiled" at runtime by the main python executable, similar to perl. Your script maintains its textfile identity. So the simple form of running a script is: python myscript It _is_ possible to create a standalone binary, though. py2exe is a common application to build an executable with. Python is theoretically capable of being used to write an OS, but that is an exercise that is probably left to theory. There are a lot of good OS'es out there that would undoubtedly perform much better than a PythonOS ever could. That doesn't mean it wouldn't be cool, though. :-) -- David Rock [EMAIL PROTECTED] pgpbDnlqYILFN.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
I am new to Python, about 1 day. And I downloaded from python.org Pythong2.4, it has the command line and junk. But what actuall program compiles the source of python into a program? Any of the programs included in the package? And also, is Python capable of writing an OS? Jon. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mamelauncher (fwd)
There actually seems to be a bit of a problem in the interaction with the system when it launches mame. If I run this: import os def run_mame_selection(selection): os.system("C:\\mame096b\\mame.exe"+ selection) #main selection = " tnzs" run_mame_selection(selection) raw_input() mame reports files missing, but I can launch the game manually- I suspect that this is some sort of error that occurs normally but is bypassed on launch and that my one-shot attempt to launch the thing cannot handle. I think I need to have a wee look at subprocess! ta Max --- Danny Yoo <[EMAIL PROTECTED]> wrote: > > Also, does this work? > > > > ## > > def run_packman(): > > os.system("C:\\mame096b\\mame.exe packman") > ^^^ > > Gaaa. My apologies: that was a typo. Correct this > (and other places > where I wrote 'packman') with whatever name you use > to explicitly tell > MAME to run PacMan. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GETTING AN _.EXE VERSION OF _.PY program to run on a machine that does not have Python installed on it.
On Mon, 12 Sep 2005, JackA wrote: > I am attaching a word document copy of this EMail which might be easier > to read and follow if your EMail window rearanges things to much. Hi Jack, Actually, please don't do that. *grin* Word documents are actually not really usable in a programming language forum. You're assuming that the recipients are using systems that are capable of running Microsoft Word. You might be surprised, but this is not necessarily true. For maximum utility, please stick to plain text formats on Python-Tutor. The page: http://expita.com/nomime.html gives some more reasons for staying with plain text, at least on technical mailing lists. Anyway, to your question: > I have created PROG.EXE from PROG.PY , but it appears NOT to be portable > in that when I try to run PROG.EXE on my wife's machine which does not > have Python installed on it I get a " See the logfile PROG.EXE log for > details". The logfile has the following ; > > > Traceback (most recent call last): > File "PROG.PY", line 364, in ? > File "PROG.PY", line 320, in Main > EOFError: EOF when reading a line Ok, I have an idea of what's going on here. Let's take a look at your 'setup.py' file. > The 6 lines of PyToExe.PY used to make PROG.EXE , is shown below > starting with ### in line #1. > > ### PyToExe.PY = file name._.PY > _.EXE > > from distutils.core import setup > import py2exe > > setup(windows=['PROG.PY']) ^^^ Ah. Change the line in your setup from using 'windows' to 'console'. You're not making a graphical "Windows" program, but one that depends on the console. Technially, a Microsoft Windows GUI program has no console, and no access to standard input or output. That's why your program breaks: it's unable to use raw_input(), since that's explicitely meant to talk to standard input. So, instead, your setup.py should look like: ## from distutils.core import setup import py2exe setup(console=['PROG.PY']) ## Best of wishes to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mamelauncher (fwd)
> Also, does this work? > > ## > def run_packman(): > os.system("C:\\mame096b\\mame.exe packman") ^^^ Gaaa. My apologies: that was a typo. Correct this (and other places where I wrote 'packman') with whatever name you use to explicitly tell MAME to run PacMan. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mamelauncher (fwd)
Hi Max, [Keeping tutor@python.org in CC. Please do not send replies only to me: make sure tutor@python.org is being included in the reply.] [Danny] >> Hint: in the defintion of run_mame_selection, there's some string >> concatenation going on here: >> >> ## >> def run_mame_selection(selection): >>os.system("C:\\mame096b\\mame.exe"+""+selection) >> ## >> >> Why the empty string? [Max] > Launching mame without any specified string from the command line > defaults to PacMan, so I was trying that out! I'm not quite sure I understand your response, and I'm also not quite sure you understood my hint. *grin* Let's back up for a moment. Ok, it sounds like if we just run mame.exe without any arguments, it should run PacMan by default. Can you try that out? ## def run_packman(): os.system("C:\\mame096b\\mame.exe") ## Does this work? I'm trying to see if we can isolate exactly where things start to break and not work as expected. Also, does this work? ## def run_packman(): os.system("C:\\mame096b\\mame.exe packman") ## Finally, what about this? ## def run_mame_selection(selection): os.system("C:\\mame096b\\mame.exe"+""+selection) def run_packman(): run_mame_selection('packman') ## As a side note: you may want to test the programs through IDLE; if you run the program through IDLE, then if you run into problems, you should still be able to see the error message that comes up. If you run the program as a standalone on Windows, debugging this is slightly more complicated because Windows closes a program's windows as soon as a program's done. Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] GETTING AN _.EXE VERSION OF _.PY program to run on a machine that does not have Python installed on it.
I am attaching a word document copy of this EMail which might be easier to read and follow if your EMail window rearanges things to much. I would like thank Dax Reyes and John Fouhy for taking the trouble to respond to my attempt to create an _.EXE from a Python program. The question now is; can the PY2EXE procedure make PROG.EXE ( Or a set of files. ) from PROG.PY that will allow PROG.EXE to run on a machine that does not have Python installed on it, and if so what has to be fixed and how?I have created PROG.EXE from PROG.PY , but it appears NOT to be portable in that when I try to run PROG.EXE on my wife's machine which does not have Python installed on it I get a " See the logfile PROG.EXE log for details". The logfile has the following ; Traceback (most recent call last): File "PROG.PY", line 364, in ? File "PROG.PY", line 320, in MainEOFError: EOF when reading a lineLines 320 and 364 are shown below. Line 364 is the last line of the program. No line reference on the EOFError was given. filename=raw_input("Enter destination and filename as > C:\Name.STR <: ") # line 320 listed in traceback log.Main() # line 360 listed in traceback log. The 6 lines of PyToExe.PY used to make PROG.EXE , is shown below starting with ### in line #1.### PyToExe.PY = file name. _.PY > _.EXEfrom distutils.core import setupimport py2exesetup(windows=['PROG.PY'])The DOS com line command was : PYTHON PyToExe.PY PY2EXE . The program, PROG.PY has no errors and runs fine under Python24, as does PROG.EXE on a Python equipped machine. Actually I can delete PROG.EXE and double click the PROG.PY icon in the Python24 folder and it runs fine. I am running an XP machine with a 1.8 GHz CPU, 700 Meg of memory and 36 Gbyte of free space on disk.I am attaching PROG.PY in case anyone has any questions on it. At some point over the course of trying to run PROG.EXE it was indicated that Python24.dll was missing so it has been copied into the DIST folder where PROG.EXE is located as well as WINDOWS\SYSTEM32\DRIVERS , WINDOWS and WINDOWS\SYSTEM .Jack Anema AFTER EXE.doc Description: MS-Word document #Leathem's thesis, Appendix A, Program for Creating Elliptical Stream Files # Line 364 = main() > On .exe traceback < Commenting t kills p shell prompts. Not option. # Line 320 = Output destination prompt > On .exe tb < # The program overwites files without notification or warning . # #!/usr/bin/python import math, array def square(x): result = x * x return result def Parse(): ## read in the command line options from optparse import OptionParser usage="%prog [OPTIONS] FILE" parser = OptionParser(usage) parser.add_option("-x", "--x-axis", type="int", dest="xa", default=10, #p.57 help="The length of the x-axis of the ellipse. Default=10") parser.add_option("-y", "--y-axis", type="int", dest="ya", default=10, help="The length of the x-axis of the ellipse. Default=10") parser.add_option("-s", "--spacing", type="int", dest="s", default=75, help="The spacing of the ellipses. Default=75") parser.add_option("-q", "--spacing2", type="int", dest="q", default=75, help="The spacing of the 2nd array of ellipses. Default=75") parser.add_option("-d", "--dwelltime", type="int", dest="d", default=100, help="Dwell time of the ion beam. Default=100") parser.add_option("-p", "--shape", type="int", dest="p", default=0, help="The basis shape; 0 : ellipse, 1 : rectangle Default=0") parser.add_option("-a", "--angle", type="float", dest="a", default=0, help="Angle of rotation of the ellipse(degrees). Default=0") #p.58 parser.add_option("-r", "--sparse", type="int", dest="r", default=0, help="Sparse Pattern; 0 : no, 1 : yes Default=0") parser.add_option("-l", "--loops", type="int", dest="l", default=1, help="The number of times to repeat the pattern. Default=1") parser.add_option("-n", "--num", type="int", dest="n", default=1, help="The number of shapes in the basis, 1 or 2. Default=1") parser.add_option("-u", "--xoffset", type="int", dest="xo", default=15, help="The x-offset of the second shape in the basis. Default=15") parser.add_option("-v", "--yoffset", type="int", dest="yo", default=15, help="The y-offse
Re: [Tutor] Where did those spaces come from?
On 9/12/05, Tom Tucker <[EMAIL PROTECTED]> wrote: Tutor, Good evening! The goal is to parse a simple file and grab column one. Then print each value horizontally separated by a comma. Why is Python adding a space padding between each value? Please see below. Thanks ahead of time. INPUT_FILE # unwanted lines removed [EMAIL PROTECTED] blah blah [EMAIL PROTECTED] blah blah [EMAIL PROTECTED] blah blah [EMAIL PROTECTED] blah blah OUTPUT DESIRED ## ,,, SCRIPT # import re input_file = open('/tmp/file','r') number_match = re.compile('^\d+\s+\w+\@') for line in input_file.readlines(): if number_match.match(line): line = re.split('\s+', line) print line[0], print ",", OUTPUT GENERATED , , , , To add to Danny's posting, I recently had to stream out an unknown list of values from a database, something like what you are doing. I created a class that formats the lines like you want and writes them out when the line gets close the the maximum length. class Line: length = 72 seperator = ', ' def __init__(self): self.reset() def reset(self): self.contents = '' def __str__(self): return str(self.contents) def __len__(self): return len(self.contents) def __add__(self, other): o = str(other) l = len(o) s = len(self.seperator) if len(self) + l + s > self.length: self.flush() if self.contents: self.contents += self.seperator self.contents += str(other) return self def flush(self): if self.contents: self._print(self.contents) self.reset() def _print(self, line): print line For your purposes, you would want to change the separator to just ','. Then you would just create an instance and add strings to it. formatted_line = Line() for line in input_file.readlines(): if number_match.match(line): line = re.split(r'\s+', line) formatted_line += line[0] else: formatted_line.flush() # clear anything left to print HTH, -Arcege-- There's so many different worlds,So many different suns.And we have just one world,But we live in different ones. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] socket question
> When I receive a 4-bytes integer using socket.recv, it is stored in > a > string. How to convert this string to a integer? Look at the struct module. Its unpack method takes a format string which defines how the data should be interpreted. Have a look at the section at the end of my file handling topic for some info and examples of usage: Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Venom / Python23.dll missing
On 9/11/05, Damien Gouteux <[EMAIL PROTECTED]> wrote: > Hi all. > I try to run Venom, a Python binding for the Irrlicht engine. But I need > python23.dll. Download a game from pygame.org Luis. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boa-Constructor
On 9/12/05, Terry Kemmerer <[EMAIL PROTECTED]> wrote: > Hey Guys, > > I am trying to pick an IDE, and it seems to me that Boa-Constructor has > great potential. Did you check Boa out of CVS? It tends not to have an intermittent schedule of releases. Luis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] socket question
ray wrote: > When I receive a 4-bytes integer using socket.recv, it is stored in a > string. How to convert this string to a integer? Take a look at unpack() in module struct. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] socket question
When I receive a 4-bytes integer using socket.recv, it is stored in a string. How to convert this string to a integer? Thanks in advance. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor