Re: [Tutor] if-else statements
Well, on the bright side, at least Python is being taught in schools. My younger sister is a CS major just starting her programming courses, and it's Java/C++ all the way. I am becoming convinced that lines of code are not only related to the number of bugs and development speed, but learning speed as well. Too much time tripping over syntax and you miss the important bits. On 10/14/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > Otherwise, it really does sound like you're just pushing your homework on > us. The jist of your questions right seem to be "This program doesn't > work: help me fix it." This is not really interesting to us. We really > want to help you get unstuck, but we don't want to do your homework. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extract plain english words from html
You could try: http://www.aminus.org/rbre/python/cleanhtml.py YMMV, as the kids say. But I did choose this over BeautifulSoup or Strip-o-gram to do this particular thing. I don't remember -why- I chose it, but there you go. Easy enough to test all three :) Oh, and if you just want a whole page prettily formatted: lynx -dump page.html > file.txt is often the easiest way. Good luck, Andrew On 10/14/05, Marc Buehler <[EMAIL PROTECTED]> wrote: > hi. > > i have a ton of html files from which i want to > extract the plain english words, and then write > those words into a single text file. > > example: > > > <... all kinds html tags ...> > > this is text > > > from the above, i want to extract the string > 'this is text' and write it out to a text file. > note that all of the html files have the same > format, i.e. the text is always surrounded by the same > html tags. > also, i am sorting through thousands of > html files, so whatever i do needs to be > fast. > > any ideas? > > marc > > > --- > The apocalyptic vision of a criminally insane charismatic cult leader > >http://www.marcbuehler.net > > > > > __ > Yahoo! Music Unlimited > Access over 1 million songs. Try it free. > http://music.yahoo.com/unlimited/ > ___ > 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] output question
Shi Mu wrote: > I found the code for class "now". I got confused by two things: > First, how did the former code I posted know to import tis module of "Now"; You told it to with the statement import now This statement tells Python to look in the directories in its path for a file called now.py and load it, assigning the resulting module object to the name 'now'. > Second. what does "\" mean following "self.year," It is a line continuation character - it means the text of the line continues on the next line. Is there anything else in now.py? Any print statements? When I run the code you have posted so far I just get one line of output. Kent > Thanks a lot! > > class now: > def __init__(self): > self.t = time.time() > self.storetime() > def storetime(self): > self.year, \ > self.month, \ > self.day, \ > self.hour, \ > self.minute, \ > self.second, \ > self.dow, \ > self.doy, \ > self.dst = time.localtime(self.t) > def __str__(self): > return time.ctime(self.t) > def __repr__(self): > return time.ctime(self.t) > def __call__(self,t=-1.0): > if t < 0.0: > self.t = time.time() > else: > self.t = t > self.storetime() > > > On 10/14/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > >>Shi Mu wrote: >> >>>After I run the following python code, I expect to have the printing such as: >>>The year is 2005 >>> >>>However, I got something like: >>>The year is 2005 >>>Fri Oct 14 17:43:31 2005 >>>Fri Oct 14 17:43:31 2005 >>>The year is 2005 >>> >>>What is the reason? >> >>Maybe coming from module 'now'? What is that? >> >>Kent >> >> >>>The code follows: >>> >>>import time >>>import now >>> >>>class today(now.now): >>>def __init__(self, y = 1970): >>> now.now.__init__(self) >>>def update(self,tt): >>> if len(tt) < 9 : >>> raise TypeError >>> if tt[0] < 1970 or tt[0] > 2038: >>> raise OverflowError >>> self.t = time.mktime(tt) >>> self(self.t) >>> >>>if __name__ == "__main__": >>>n = today() >>>print "The year is", n.year >>>___ >>>Tutor maillist - Tutor@python.org >>>http://mail.python.org/mailman/listinfo/tutor >>> >>> >> >>___ >>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] output question
On 10/14/05, Shi Mu <[EMAIL PROTECTED]> wrote: I found the code for class "now". I got confused by two things:First, how did the former code I posted know to import tis module of "Now";Second. what does "\" mean following "self.year ,"Thanks a lot!class now: def __str__(self):return time.ctime(self.t)def __repr__(self):return time.ctime(self.t) you mean you didn't write the "former code?" why are you asking for help with code that you did not write? your output is caused by the 2 now methods above. the '\' is the continuation character in Python. are you learning Python on your own? -- wesley- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"Core Python Programming", Prentice Hall, (c)2006,2001http://corepython.comwesley.j.chun :: wescpy-at-gmail.comcyberweb.consulting : silicon valley, cahttp://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] output question
I found the code for class "now". I got confused by two things: First, how did the former code I posted know to import tis module of "Now"; Second. what does "\" mean following "self.year," Thanks a lot! class now: def __init__(self): self.t = time.time() self.storetime() def storetime(self): self.year, \ self.month, \ self.day, \ self.hour, \ self.minute, \ self.second, \ self.dow, \ self.doy, \ self.dst = time.localtime(self.t) def __str__(self): return time.ctime(self.t) def __repr__(self): return time.ctime(self.t) def __call__(self,t=-1.0): if t < 0.0: self.t = time.time() else: self.t = t self.storetime() On 10/14/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > After I run the following python code, I expect to have the printing such > > as: > > The year is 2005 > > > > However, I got something like: > > The year is 2005 > > Fri Oct 14 17:43:31 2005 > > Fri Oct 14 17:43:31 2005 > > The year is 2005 > > > > What is the reason? > > Maybe coming from module 'now'? What is that? > > Kent > > > > > The code follows: > > > > import time > > import now > > > > class today(now.now): > > def __init__(self, y = 1970): > > now.now.__init__(self) > > def update(self,tt): > > if len(tt) < 9 : > > raise TypeError > > if tt[0] < 1970 or tt[0] > 2038: > > raise OverflowError > > self.t = time.mktime(tt) > > self(self.t) > > > > if __name__ == "__main__": > > n = today() > > print "The year is", n.year > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > > ___ > 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] output question
Shi Mu wrote: > After I run the following python code, I expect to have the printing such as: > The year is 2005 > > However, I got something like: > The year is 2005 > Fri Oct 14 17:43:31 2005 > Fri Oct 14 17:43:31 2005 > The year is 2005 > > What is the reason? Maybe coming from module 'now'? What is that? Kent > > The code follows: > > import time > import now > > class today(now.now): > def __init__(self, y = 1970): > now.now.__init__(self) > def update(self,tt): > if len(tt) < 9 : > raise TypeError > if tt[0] < 1970 or tt[0] > 2038: > raise OverflowError > self.t = time.mktime(tt) > self(self.t) > > if __name__ == "__main__": > n = today() > print "The year is", n.year > ___ > 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] extract plain english words from html
Marc Buehler wrote: > hi. > > i have a ton of html files from which i want to > extract the plain english words, and then write > those words into a single text file. If you just want the text from a single tag in the document then BeautifulSoup will work well, as Danny and Bob suggest. If you have many tags containing text and you want all the text, you might like StripOGram http://www.zope.org/Members/chrisw/StripOGram or this succinct example from Python Cookbook 2nd edition: from sgmllib import SGMLParser class XMLJustText(SGMLParser): def handle_data(self, data): print data XMLJustText().feed(open('text.xml').read()) Kent > > example: > > > <... all kinds html tags ...> > > this is text > > > from the above, i want to extract the string > 'this is text' and write it out to a text file. > note that all of the html files have the same > format, i.e. the text is always surrounded by the same > html tags. > also, i am sorting through thousands of > html files, so whatever i do needs to be > fast. > > any ideas? > > marc > > > --- > The apocalyptic vision of a criminally insane charismatic cult leader > >http://www.marcbuehler.net > > > > > __ > Yahoo! Music Unlimited > Access over 1 million songs. Try it free. > http://music.yahoo.com/unlimited/ > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] output question
After I run the following python code, I expect to have the printing such as: The year is 2005 However, I got something like: The year is 2005 Fri Oct 14 17:43:31 2005 Fri Oct 14 17:43:31 2005 The year is 2005 What is the reason? The code follows: import time import now class today(now.now): def __init__(self, y = 1970): now.now.__init__(self) def update(self,tt): if len(tt) < 9 : raise TypeError if tt[0] < 1970 or tt[0] > 2038: raise OverflowError self.t = time.mktime(tt) self(self.t) if __name__ == "__main__": n = today() print "The year is", n.year ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extract plain english words from html
At 03:50 PM 10/14/2005, Marc Buehler wrote: >hi. > >i have a ton of html files from which i want to >extract the plain english words, and then write >those words into a single text file. http://www.crummy.com/software/BeautifulSoup/ will read the html, let you step from tag to tag and extract the text. Almost no effort on your part. [snip] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extract plain english words from html
On Fri, 14 Oct 2005, Marc Buehler wrote: > i have a ton of html files from which i want to extract the plain > english words, and then write those words into a single text file. Hi Marc, The BeautifulSoup parser should be able to do what you want: http://www.crummy.com/software/BeautifulSoup/ For example: ## >>> from BeautifulSoup import BeautifulSoup >>> import urllib >>> import re >>> soup = BeautifulSoup(urllib.urlopen('http://python.org/index.html')) >>> for chunk in soup.fetch('a'): ... print chunk.fetchText(re.compile('.+')) ... [] ['Search'] ['Download'] ['Documentation'] ['Help'] ['Developers'] ['Community'] ['SIGs'] ['What is Python?'] ['Python FAQs'] ['Python 2.4'] ['(docs)'] ['Python 2.3'] ['(docs)'] ['Python 2.2'] ['(docs)'] ['MacPython'] ['Jython'] ... [lots of output here] ## And this allows us to quickly get all the hyperlinked text off the Python.org web site. It's not perfect, but it can deal surprisingly well with ugly HTML. Hope this helps! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] extract plain english words from html
hi. i have a ton of html files from which i want to extract the plain english words, and then write those words into a single text file. example: <... all kinds html tags ...> this is text from the above, i want to extract the string 'this is text' and write it out to a text file. note that all of the html files have the same format, i.e. the text is always surrounded by the same html tags. also, i am sorting through thousands of html files, so whatever i do needs to be fast. any ideas? marc --- The apocalyptic vision of a criminally insane charismatic cult leader http://www.marcbuehler.net __ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries in classes
On Fri, 14 Oct 2005, Luke Jordan wrote:> I'm trying to have functions to create, edit and store dictionaries > within a class. i 2nd danny's motion: make your dictionary an instance attribute (unique to that instance) rather than a class attribute (shared amongst all instances), and 2ndly, don't use 'dict' because that is a built-in (factory) function: class N: def __init__(self): self.myDict = {}n = N()... then pickle 'n' as danny has described.good luck!-- wesley- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"Core Python Programming", Prentice Hall, (c)2006,2001 http://corepython.comwesley.j.chun :: wescpy-at-gmail.comcyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python ncurses vs OS X Tiger's xterms.
> On Fri, Oct 14, 2005, Alan Gauld wrote: >>Bill this is a guess but try setting the terminal type to vt220 >>or vt330 or similar rather than xterm. Does that make any difference? > > I haven't tried fiddling the terminal type, and would prefer not > to unless it's the last resort. The reason I suggested oit is that its one of the things thats platform dependant and so setting a standard terminal setting on all platforms might show up the differences. In particular the Apple Terminal program versus xterm, but even an xterm can be defined difeerently on different Unix flavours. This is one reason I have a line in my profile/cshrc files to force term type to v220, it just makes life more consistent... > The ncurses libraries support termcap, but I think that all > current versions of curses use terminfo which has many more termcap or terminfo the point was that the beghaviour is not really in curses but in the terminal definitions stored in those databases. Of course curses tries hard to hide those differences but ultimately is only as capable as the capabilities that have been defined. > I suspect that the problem is more related to keyboard mappings > in the Apple X11 implementation than it does with the terminfo > and terminal type settings as the same applications work fine As a matter of interest what does trhe apple Terminal and xterm claim the terninal type to be? (I should just go downstairs and boot my iBook! :-) > there is something I can handle in my python ncurses routines > than if I have to dig into the keyboard mapping stuff. Absolutely and curses is supposede to do that, but when debugging curses(*) I've found it useful top know exactly what terminal curses thinks its playing with. (*)And I mean curses I've never used ncurses in anger... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries in classes
On Fri, 14 Oct 2005, Luke Jordan wrote: > I'm trying to have functions to create, edit and store dictionaries > within a class. Here's a small example of a class: ## class Person: def __init__(self, name): self.name = name ## Let's try pickling an instance of it: ## >>> p = Person("Luke") >>> pickle.dumps(p) "(i__main__\nPerson\np0\n(dp1\nS'name'\np2\nS'Luke'\np3\nsb." ## Given a string like that, let's see if we can unpickle it back to an object instance: ## >>> p2 = pickle.loads("(i__main__\nPerson\np0\n(dp1\nS'name'\np2\nS'Luke'\np3\nsb.") >>> p2 <__main__.Person instance at 0x4048d8cc> >>> p2.name 'Luke' ## > I don't know why I can't figure out how to make the dictionary an > attribute of the class, or if that's even possible. You may want to make it an attribute of the class instance, and not necessarily one of the class itself. A class attribute is shared among all instances, and that's probably not what you want. The example above shows how to initialize an attribute of a class instance, and that's probably what you've been missing. If you have more questions, please feel free to ask! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] dictionaries in classes
Hi, Another stumped beginner here. I'm trying to have functions to create, edit and store dictionaries within a class. What I can't figure out is how to retain the edits after making them. I think it has something to do with namespace. Ideally I'd like to pickle class instances and be able to access each instance's unique dictionaries through a classInst.dict arrangement. I don't know why I can't figure out how to make the dictionary an attribute of the class, or if that's even possible. Does the dict have to be a separate pickled file? I've tried setting the dict in these namespaces: class N: dict = {} class N: def func(self): dict = {} but neither of these is working for me. If I make the dict global, then all class instances could edit it, which is not what I'm shooting for either. I'm out of ideas, and I sense that there is something basic that I either don't know or am overlooking. Thanks in advance. Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] question about pychart
Hey there, i have a simple app that plots some numbers sent by a field sensor with respect to time. i am trying to do this in pychart, but the problem is, when the numbers come in, they do so at almost random times. y shows the value sent by the sensor x plots the time that the value came in. what happens is that the plots are spaced evenly throughout the x axis. so it always looks like an even amount of time when most often, it isn't i need a way to make it plot out the x so that when a lot of values come in at close to the same time, it looks more like that on the graph. i looked at the docs where the examples show that this can be done, the example uses a log style to the plot. it looks like this. http://home.gna.org/pychart/examples/scattertest.png mostly the graph on the right my chart shows just a plot of x=datetime y=value, someone have an idea about how i can get more realistic looking values? thanks shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] comiling python to microchip?
If you mean a small one like a microcontroller (ARM, AVR, Dragonball, 68x000) then no. If you're using, say, embedded Linux on ARM, then it probably works, here's a link: http://www.vanille.de/projects/python.spy Hope it helps, Hugo Jeff Peery wrote: > is it possible to take python code and compile it for use in a > microprocessor? > > > > > ___ > 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] Python 2.4.1 on Mndrk Linux 10.1 - path
Hi Andy, > Behalf Of Andy Dani > > Python 2.3.2 came with the linux distribution which is located in > /usr/lib. > > Installed 2.4.1 in /usr/local/Python-2.4.1 > > updated /etc/profile path so IDLE or "python" would point to the > latest version (2.4.1). > > PATH="$PATH:/usr/local/Python-2.4.1/:." > export PATH > > But it is still pointing to the old one unless I go > /use/local/Python-2.4.1/python. > > I want to be able to launch and run python 2.4.1, from the user > account so I do not need to be "root" every time. The default install of python on Mandrake probably install the python executable in /usr/bin/python. /usr/bin/ is in your PATH, so if you put PATH=$PATH:/usr/local/Python-2.4.1 in /etc/profile it will still pick up the default python install. Try typing 'which python' at the command line and see what it picks up. Chances are it will be /usr/bin/python. You could solve this by either putting PATH=/path/to/my/wanted/python/dir:$PATH in /etc/profile (or ~/.bash_profile) or by putting an alias in ~/.bashrc, such as 'alias python='path/to/my/wanted/python/dir/python'. What I must stress is that you do not overwrite your default python installation, leave it as it is, otherwise many of mandrakes GUI tools will no work. I hope that helps, feel free to ask more questions about this as I have had to overcome the same issue on RHEL serveral times. Hth, Nick . ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python 2.4.1 on Mndrk Linux 10.1 - path
> I want to be able to launch and run python 2.4.1, from the user account so I > do not need to be "root" every time. I use Ubuntu Linux and Python 2.4.1 comes with it. All I need to do is to open a terminal and type python and press enter. What's the problem? Norman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] if-else statements
> > For some reason, the months that have 31 days work fine, but the > > months that have 28/30 do not work. > > How do you know that? > > Show us why you think there's a problem in the program. We have our own > opinions, of course, but it'll be very helpful if you try explaining how > you're thinking this through. Why do you think that the program is > buggy? As one more hint: try simplifying your problem. Can you change the program to handle just January, and see if it can handle January dates well? Next, can you modify your working program to handle both January and February? Does it work on January and February dates correctly? Next, can you modify your program to handle January, February, and March? Once you figure that out, then it should be a little easier to scale the program to all the months, and you should be able to better build on a program that you can progressively test. What we're trying to show you are general techniques for solving hard problems. See: http://www.math.utah.edu/~alfeld/math/polya.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python ncurses vs OS X Tiger's xterms.
On Fri, Oct 14, 2005, Alan Gauld wrote: >Bill this is a guess but try setting the terminal type to vt220 >or vt330 or similar rather than xterm. Does that make any difference? I haven't tried fiddling the terminal type, and would prefer not to unless it's the last resort. >curses uses the termcap database to determine how int interacts with >the keyboard so changing the terminal type to somethingwell defined >might make a difference? The ncurses libraries support termcap, but I think that all current versions of curses use terminfo which has many more options under ncurses than the original AT&T versions had. I suspect that the problem is more related to keyboard mappings in the Apple X11 implementation than it does with the terminfo and terminal type settings as the same applications work fine from Linux desktops. I've looked into xmodmap, and the X Resources that xterms support, but it would be much nicer if there is something I can handle in my python ncurses routines than if I have to dig into the keyboard mapping stuff. Bill -- INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC UUCP: camco!bill PO Box 820; 6641 E. Mercer Way FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 URL: http://www.celestial.com/ ``It's not what you pay a man but what he costs you that counts.'' Will Rogers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] if-else statements
> I'm having some trouble with my if, else statements. Ok, let's pause for a moment: it seems like you're having problems with more fundamental problems than just simple if/else statements. In the past questions you've written: http://mail.python.org/pipermail/tutor/2005-October/041863.html http://mail.python.org/pipermail/tutor/2005-October/042250.html you haven't really responded back in a way that helps us understand why you're getting stuck. Let's have some give and take here. Is there something you're not understanding from the other people's replies? If so, ask! Otherwise, it really does sound like you're just pushing your homework on us. The jist of your questions right seem to be "This program doesn't work: help me fix it." This is not really interesting to us. We really want to help you get unstuck, but we don't want to do your homework. > For some reason, the months that have 31 days work fine, but the months > that have 28/30 do not work. How do you know that? Show us why you think there's a problem in the program. We have our own opinions, of course, but it'll be very helpful if you try explaining how you're thinking this through. Why do you think that the program is buggy? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] First post
On Fri, 14 Oct 2005, Anthoni Shogan wrote: > this is my first post as a test.. Hi Anthoni, Ok, we see you. In general, it's usually not a good idea to write test messages on these kinds of mailing lists: it adds to the "noise" in the channel. Anyway, do you have a question about learning Python? Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python 2.4.1 on Mndrk Linux 10.1 - path
Python 2.3.2 came with the linux distribution which is located in /usr/lib. Installed 2.4.1 in /usr/local/Python-2.4.1 updated /etc/profile path so IDLE or "python" would point to the latest version (2.4.1). PATH="$PATH:/usr/local/Python-2.4.1/:." export PATH But it is still pointing to the old one unless I go /use/local/Python-2.4.1/python. I want to be able to launch and run python 2.4.1, from the user account so I do not need to be "root" every time. One more question, what is the significance of "import readline" in pythonrc.py file? Any harm if I comment that line out? this line gives a problem when I launch the 2.4.1 from /usr/loca/Python-2.4.1 directory. Thanks - -- ___ Search for businesses by name, location, or phone number. -Lycos Yellow Pages http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "Decompile" pyc file
Bernard Lebel wrote: > Hello, > > Is there a way to "decompile" a pyc file? I have a big problem where > the py file was lost, but the pyc file is instact. I would need to > extract the source code from the pyc file. Google 'python decompiler' try http://www.freshports.org/devel/decompyle/ or the commercial service at http://www.crazy-compilers.com/decompyle/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] "Decompile" pyc file
Hello, Is there a way to "decompile" a pyc file? I have a big problem where the py file was lost, but the pyc file is instact. I would need to extract the source code from the pyc file. Thanks for any suggestion Beranrd ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __slots__
> Can't you read the data from the binary file as needed? > For example build a table of object ids versus file locations > and then use seek() to go to an object and load it from file > on demand? > > > So, in doing so, I end up with a whole lot of objects, but it's a > > whole lot of objects I can easily use. > > Easy to use but hoggingmemory. If you make the init method > read the file then instantiating on demand becomes pretty easy too. Haha, that's pretty danged funny. I just spent ages ripping out all my file reads on instantiation, so that when a new object was created, it didn't care where the data came from but I'm happy with my decision to let a function do it for now. I might just clarify my intent. It's just a library to facilitate movement of music on/off an iPod without loading up iTunes, or ml_ipod for Winamp or similar. So to do that, I've created objects that are just subclassed lists like so - (they're actually subclasses of a subclass of list, so I've just c & p ed the inherited bits). class MHLP(list): """ Type: Playlist list Tuple format: [0] header_id (4 char string) [1] header_length (int) [2] number_of_playlists (int) <--(Includes special 'library' playlist which is hidden) Note: Library playlist must be first child. """ def __init__(self, data): self.extend(data) self._setRankAttr() def _setRankAttr(self): self.isMaster = True self.isSlave = True self.slaves = [] self.masters = ['mhsd'] def addSlave(self, slave): self.slaves.append(slave) def writeMe(self, f): hexed = struct.pack(self.pattern, self.pData) f.write(hexed) if self.isMaster: for slave in self.slaves: slave.writeMe(f) The setrank part is my way of preserving the hierachy of the file. It parses the database, and returns a list of objects, which is then iterated over to set the relationships, via this function - def setRelationships(headerList): masterStack = [] for dataObject in headerList: if dataObject.isSlave: while not masterStack[-1][0] in dataObject.masters: masterStack.pop() masterStack[-1].addSlave(dataObject) if dataObject.isMaster: masterStack.append(dataObject) What happens when a user adds a song to the iPod via this is that the ID3 tags are read, the song is copied across, and the various MHIT & MHOD objects created, and appropriate references inserted in the correct object's slaves list. A Song object is also created just unifying the methods necessary to add/remove/edit the song's details; and making available the useful data contained in the fiddlier rawer objects without exposing the messy internals. A song header is 66 items long, and about 30 of them have unknown function at this point. When a song is added, a reference to it (an integer, not a Python reference) needs to be added in about 5/6 objects, plus child counts need to be updated; hence why holding all the info in memory seemed to be the simplest solution (for me to develop). I'm writing for the 80% of cases where at most there'll be 60,000 objects, usually 12,000, and as not overly many people have USB 2.0, multiple read/writes to the iPod are something I wish to minimise. Writing to a local drive isn't something I want to rely on either, as hopefully, I'll be able to get this running directly from the iPod via a Linux install. Linux can read NTFS but not write it, I believe. I'm pie in the sky dreaming at the moment, I have to finish adding struct patterns for the rest of the weird objects. > Its just the kind of stuff described above. Instead of ac tually > holding the objects hold a reference to the class and the id(a tuple?), > then when you actually need the object instantiate it and let the > constructor fetch the data on demand. That way you only need the > top level objects in RAM - the current playlist or song selection say.. I must admit, I'm also not too sure about how to maintain the correct order in a simple manner using that late evaluation stuff; especially with adding new objects. I was thinking of perhaps a whole bunch of nested lists, but I don't tend to do well with nested lists. :/ I suspect I'm getting distracted by premature optimisation, I've been playing with MPLab's simulator, and trying to write tight ASM is getting to me. :) Thank you for your advice. Regards, Liam Clarke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] redemo.py and r'python\.org'
Dick Moores wrote: > Kent Johnson wrote at 19:21 10/13/2005: > >> > BTW in redemo.py, what do the checkboxes VERBOSE, LOCALE, and DOTALL >> > mean? (I understand IGNORECASE and MULTILINE.) >> >> http://docs.python.org/lib/node115.html > > > OK, but that didn't help with LOCALE. From > http://en.wikipedia.org/wiki/Locale > LOCALE seems to be something I don't need to worry about for a while. LOCALE Make \w, \W, \b, \B, \s and \S dependent on the current locale. Locale is a setting that affects some operations that differ in different cultures, for example whether a . or , is used as a decimal separator and what the money symbol is. You can access locale settings with the locale module. The list of word and space characters can differ by locale. This affects the meaning of the \ escapes noted above. Even setting the locale to 'en' (from the default 'C' locale) changes the default letters: >>> import string, locale >>> string.letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> locale.setlocale(locale.LC_ALL, 'en') 'English_United States.1252' >>> string.letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\x83\x8a\x8c\x8e\x9a\x9c\x9e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\ xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf 6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff' >>> Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to create GUI for Python progs
It seems to depend on what you want easygui --- Very simple, very easy to set up, but is NOT event driven (ie the program uses it much like it would use raw_input but with drop boxes. All other guis are event driven - that is the gui has the main loop, and when it detects (a button click) it fires off a request to the rest of the program to do something. The main frameworks (ie they provide widgets like buttons so you do not have to write your own button code) pyQT --- Extrememly well suported and mature, Has a good drag and drop developer. Is free for Linux / open source use. Commercially is a bit more confused. tkinter The default python Gui but it might be changing - see frederick Lundh's IDE for what can be done in it. WxPython - Simialr to pyQt, widgets bigger than tkinter Wrappers around the above frameworks for ease PythonCard --- As recommended above. There are a plethora of gui interfaces (http://wiki.python.org/moin/GuiProgramming) Almost as many as web frameworks ! I suggest starting with easygui if you just want pop up dialogs, otherwise take a day or two to get to grips with QT. with a drag and drop editor it is surprisingly good. There is a tutorial by a B Rempt somewhere on line. On 10/13/05, Olexiy Kharchyshyn <[EMAIL PROTECTED]> wrote: > > I'm really confused on the issue how to create windows, forms, etc. in > Python & can't find any manual for that. > Could you possibly advise me smth useful? > -- > Best regards, > > Olexiy Kharchyshyn > > [EMAIL PROTECTED] > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- -- Paul Brian m. 07875 074 534 t. 0208 352 1741 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing variable to python script
There are several approaches ranging from the simple but limited to rather advanced. raw_input is the simplest but it is to be deprecated, and more importantly it limits you to entering commands after the script is running. automation becomes harder $ myscript Those args are put into a list called sys.argv where sys.argv[0] is the name of the script you ran and any subsequent ones are sys.argv[1] {2] etc etc However my favourite is optparse module, which allows you to set up what options you like (for example $ myscript -q --outfile=/home/foo.txt) and will carefully check their validity, provide defaults, convert to floats etc where needed, and there is a cool easygui addon. On guido's Artima weblog there is a good article on using special main cases - it is pretty "deep" so do not worry if you cannot put it all to use - at least you know where you can get to. The above $ myscript is the best way to call a script, because you can run it from the command line automatically, manually, and if you use the convention of wrapping the script in a main() function, then putting this at the bottom of the file if __name__ == '__main__': main() (ie you have a function addTwoNumbers(a,b), and main takes args[1] and args[2] and passes them to addTwoNumbers) Then main() will only be run when the script is called from the command line, meaning the same code can be import'ed and addTwoNumbers can be called from any other python program. HTH On 10/14/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > > i want to pass an argument (a number) to a python > > script when running it: > >> python script.py > > > > i want to be able to use within script.py > > as a parameter. > > > > how do i set this up? > > This is covered in the 'talking to the user' topic in my tutorial. > > The short answer is use sys.argv > > 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 > -- -- Paul Brian m. 07875 074 534 t. 0208 352 1741 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: if-else statements
My apologies - I keep failing to reply-all. -- Forwarded message -- From: paul brian <[EMAIL PROTECTED]> Date: Oct 14, 2005 10:04 AM Subject: Re: [Tutor] if-else statements To: Andre Engels <[EMAIL PROTECTED]> I would also suggest you look at either datetime module or the mx.DateTime modules (from egenix). They are both very good and contain plenty of error checking for just such things, aas well as nicely overriding operators like + (so you can add 2 weeks to a date easily). >>> import datetime We can try an invlaid date and trap the error (using try: Except: statements) >>> datetime.date(2005,02,30) Traceback (most recent call last): File "", line 1, in ? ValueError: day is out of range for month A valid date >>> d = datetime.date(2005,02,27) And shown in a easy to read format >>> d.strftime("%A %B %d %Y") 'Sunday February 27 2005' cheers On 10/14/05, Andre Engels <[EMAIL PROTECTED]> wrote: > 2005/10/14, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > > Hello > > > > I'm having some trouble with my if, else statements. For some reason, the > > months that have 31 days work fine, but the months that have 28/30 do not > > work. Am I doing something wrong? it is supposed to take a date as an > > input like 9/31/1991 and then say that the date is not valid because > > september only has 30 days. > > First hint: > Where is 'month' used in your program? The answer is: nowhere. It > should be used. Why? > > Second hint: > Currently, the program checks each date first for validity with > respect to January, then throws the outcome away to do the same with > February, etcetera upto December. Thus, the final outcome says whether > the date is correct in December, not whether it is correct in the > given month. > > (actual code below) > > > import string > > > > def main(): > > # get the day month and year > > month, day, year = input("Please enter the mm, dd, : ") > > date1 = "%d/%d/%d" % (month,day,year) > > > > months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] > > > > if day <= months[1]: > > d = "valid" > > else: > > n = "not valid" > > > > if day <= months[2]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[3]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[4]: > > d = "valid" > > else: > > n = "not valid" > > > > if day <= months[5]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[6]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[7]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[8]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[9]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[10]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[11]: > > d = "valid" > > else: > > d = "not valid" > > > > if day <= months[12]: > > d = "valid" > > else: > > d = "not valid" > > > > print "The date you entered", date1, "is", d +"." > > > > main() > > Correct and shortened code: > > Instead of the whole line "if day <= months[1]"... series of > if-then-else statements, use only one statement, namely: > > if day <= months[month]: >d = "valid" > else: >d = "not valid" > > -- > Andre Engels, [EMAIL PROTECTED] > ICQ: 6260644 -- Skype: a_engels > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- -- Paul Brian m. 07875 074 534 t. 0208 352 1741 -- -- Paul Brian m. 07875 074 534 t. 0208 352 1741 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] guidance for web site development
I am also looking for a good tutorial on this subject. Have you tried http://www.modpython.org/ ? I think that the mod_python mailing list will be a better place to ask. I'm going to. Johan nitin chandra wrote: > Hi!... >i am new to Python and i want to develop a website with forms; data >submitted through forms will be stored in PostgreSQL. >I am working on deriviant of FC3, OpenLX. >I have Apache 2.0.54 version installed, which is pre-configured with >mod_python. >how do i load and view my .py/.html web page (file) on the browser. >i need the initial hand holding/guidance of how to start, configure , >and develop modules. > >thanks in advance. > >Nitin Chandra >___ >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] if-else statements
2005/10/14, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > Hello > > I'm having some trouble with my if, else statements. For some reason, the > months that have 31 days work fine, but the months that have 28/30 do not > work. Am I doing something wrong? it is supposed to take a date as an > input like 9/31/1991 and then say that the date is not valid because > september only has 30 days. First hint: Where is 'month' used in your program? The answer is: nowhere. It should be used. Why? Second hint: Currently, the program checks each date first for validity with respect to January, then throws the outcome away to do the same with February, etcetera upto December. Thus, the final outcome says whether the date is correct in December, not whether it is correct in the given month. (actual code below) > import string > > def main(): > # get the day month and year > month, day, year = input("Please enter the mm, dd, : ") > date1 = "%d/%d/%d" % (month,day,year) > > months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] > > if day <= months[1]: > d = "valid" > else: > n = "not valid" > > if day <= months[2]: > d = "valid" > else: > d = "not valid" > > if day <= months[3]: > d = "valid" > else: > d = "not valid" > > if day <= months[4]: > d = "valid" > else: > n = "not valid" > > if day <= months[5]: > d = "valid" > else: > d = "not valid" > > if day <= months[6]: > d = "valid" > else: > d = "not valid" > > if day <= months[7]: > d = "valid" > else: > d = "not valid" > > if day <= months[8]: > d = "valid" > else: > d = "not valid" > > if day <= months[9]: > d = "valid" > else: > d = "not valid" > > if day <= months[10]: > d = "valid" > else: > d = "not valid" > > if day <= months[11]: > d = "valid" > else: > d = "not valid" > > if day <= months[12]: > d = "valid" > else: > d = "not valid" > > print "The date you entered", date1, "is", d +"." > > main() Correct and shortened code: Instead of the whole line "if day <= months[1]"... series of if-then-else statements, use only one statement, namely: if day <= months[month]: d = "valid" else: d = "not valid" -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] guidance for web site development
nitin chandra wrote: > Hi!... >i am new to Python and i want to develop a website with forms; data >submitted through forms will be stored in PostgreSQL. >I am working on deriviant of FC3, OpenLX. >I have Apache 2.0.54 version installed, which is pre-configured with >mod_python. >how do i load and view my .py/.html web page (file) on the browser. >i need the initial hand holding/guidance of how to start, configure , >and develop modules. > >thanks in advance. > >Nitin Chandra >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > Take a look at TurboGears, it sounds promising. -- Anthoni Shogan Fame is a vapor; popularity an accident; the only earthly certainty is oblivion. -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] guidance for web site development
Hi!... i am new to Python and i want to develop a website with forms; data submitted through forms will be stored in PostgreSQL. I am working on deriviant of FC3, OpenLX. I have Apache 2.0.54 version installed, which is pre-configured with mod_python. how do i load and view my .py/.html web page (file) on the browser. i need the initial hand holding/guidance of how to start, configure , and develop modules. thanks in advance. Nitin Chandra ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor