Re: [Tutor] Python program with multiple answers

2011-05-11 Thread Patrick Sabin
* Create a list. * Each time, the user gets an answer add it to the list * At the end of the program: sort the list and print each element of it - Patrick On 2011-05-11 12:49, Johnson Tran wrote: Hi Guys, I've been working on a Python program where I create an 8 ball that will allow you to

Re: [Tutor] Nodes and Queues?

2011-05-11 Thread Patrick Sabin
A queue is a data structure, which keeps track of multiple objects. You can add data to a queue or you can remove it. When you remove an object from a queue you get the element which you have added first. Therefore, it is also called FIFO (First In First Out). A basic implementation could look

Re: [Tutor] GUI + python program

2011-02-14 Thread Patrick Sabin
You have a lot of options: GUI: Any major gui toolkit will do the job. It's probobly easiest to stick with tkinter. HTML Template: Use a template language, e.g. mako or django templates Pdf Templates: Reportlab is an option. File Access: Of course you could just open a file and write to it, b

Re: [Tutor] scraping and saving in file

2010-12-30 Thread Patrick Sabin
On 2010-12-29 10:54, Tommy Kaas wrote: It works fine but besides # I also get spaces between the columns in the text file. How do I avoid that? You could use the new print-function and the sep keyword argument, e.g.: from __future__ import print_function f = open("filename", "w") print("1", "

Re: [Tutor] Sequences of letter

2010-04-11 Thread Patrick Sabin
So far this is what I have: letras = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","z"] letra1 = 0 letra2 = 0 letra3 = 0 for i in letras: for j in letras: for k in letras: print letras[letra1]+letras[letra2]+letras[letra3

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Patrick Sabin
ipAddress = "123.123.123.123" emails = ipAddress.GetEmailAddresses() Not exactly sure, what you want, but maybe something like this? class mystr(str): def GetEmailAddresses(self): return [str(self)] ipAddress = mystr("123.123.123.123") emails = ipAddress.GetEmailAddresses()

[Tutor] Resetting the namespace

2010-03-08 Thread Patrick Sabin
I found this piece of code, which completely puzzles me, in the pdb module of the trunk: class Pdb(bdb.Bdb, cmd.Cmd): ... def _runscript(self, filename): # The script has to run in __main__ namespace (or imports from # __main__ will break). # # So we clear

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Giorgio wrote: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x -> ok s = 'Hallo World' how is encoded? I am not 100% sure,

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Mmm ok. So all strings in the app are unicode by default? Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Do you know if there is a function/method i can use to check encoding of a string? AFAIK such a function doesn't exis

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Giorgio wrote: i am looking for more informations about encoding in python: i've read that Amazon SimpleDB accepts every string encoded in UTF-8. How can I encode a string? And, what's the default string encoding in python? I think the safest way is to use unicode strings in your application

Re: [Tutor] Unexpected iterator

2009-11-12 Thread Patrick Sabin
Jeff R. Allen wrote: a, b = 0 Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable I understand why it doesn't work, but I don't understand the wording of the exception. Could someone explain how I accidentally introduced iteration into the picture

Re: [Tutor] class Knights vs class Knights(object)

2009-11-07 Thread Patrick Sabin
Wayne Werner wrote: and my question is what is the difference between the two? Is there a difference other than one is an object the other is an instance? I googled "python object vs. instance" and didn't find anything terribly useful. Yes there is a difference. One class inherits from objec

Re: [Tutor] help with alternate execution

2009-10-02 Thread Patrick Sabin
wrobl...@cmich.edu wrote: Thank you for the reply.. I tried putting the print repr(n) before I defined 'n' with raw_input. My script looks like this-- def divisible(n): if n%3 == 0: print n, "is divisible by 3" else: print n, "is not divisible by 3" n= raw_input("enter

Re: [Tutor] code improvement

2009-09-29 Thread Patrick Sabin
You could invert your if-expressions, e.g. instead of if query_company_name: ... you could write if not query_company_name: return adresses, company ... This way you could save some indentation. If you want to get rid of the for loops, you could look at list comprehensions, e

Re: [Tutor] real world decorators

2009-09-21 Thread Patrick Sabin
John wrote: Hi, I think I understand what decorators are and how they work. Maybe it's just me but I don't know where I'd use them in my real world programming. I see how they work with profile or coverage but does anyone have real world uses. @classmethod, @staticmethod, @property, @abs

Re: [Tutor] Using the time module to extract a semi-random number

2009-09-17 Thread Patrick Sabin
Laurii wrote: Hello all, I am currently reading through the Tutorial for Non-Programers by Josh Cogliati. I have had great success until now. The exercise to modify a number guessing program from a fixed number "number = 78" to using the time module and use the seconds at the time the prog

Re: [Tutor] Fwd: Executing a command from a specific directory

2009-09-16 Thread Patrick Sabin
Ansuman Dash schrieb: Hello Everybody, In Python scripting, how can I execute a command (which can be run from spcific directory) and then retrieve the result (after executing the command it give the command is executed successfull or not), so that I can validate it. Thanks, AD import

Re: [Tutor] Image manipluation (On-the-fly thumbnail creation)

2009-09-15 Thread Patrick Sabin
dan06 wrote: I've recently delved into python, about a week or so ago; I'm trying to figure out how to create on-the-fly thumbnails. Are there python standard library modules I could/should use or should I use external libraries like: GD, Gimp, or ImageMagick? When I needed thumbnails of my i

Re: [Tutor] Sorting 2-d data

2009-09-13 Thread Patrick Sabin
> But for sorting the list with the first element as key, I tried it using just mylist.sort() without the lambda, and its working also. Then why use the lambda? There is a little difference between those two variations. Example: >>> sorted([[1,2],[1,3],[1,1]]) [[1, 1], [1, 2], [1, 3]] >>> s

Re: [Tutor] include remote module

2009-09-12 Thread Patrick Sabin
Maybe something like this helps you to solve your problem: # get code via http, etc. code = """ def blah(): print 'blah' print 'hello' blah() """ compiled_code = compile(code, 'filename', 'exec') exec(compiled_code) This way you could execute some code from a web client, but the client wo

Re: [Tutor] pygtk

2009-09-08 Thread Patrick Sabin
The official docs http://www.pygtk.org/pygtk2tutorial/index.html http://library.gnome.org/devel/pygtk/stable/ worked for me. - Patrick Ajith Gopinath schrieb: I will appreciate , if somebody guides me to a proper doc. on pygtk for 2.5/2.6. I am currently unable to find a good doc for the same