[Tutor] [tutor] dictionary
Hi, how can i print a dictionary, sorted by the values? - Поличба 666. Само в кината. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Combo Box in Tkinter
Check out Python MegaWidgets (pmw.sourceforge.net). On 07/06/06, Keo Sophon <[EMAIL PROTECTED]> wrote: > Hi, > > Is there any Combo Box in Tkinter? I looked for it but only found list box. > Might it be list box having any option to make itself as a combo box? > > Thanks, > Phon > ___ > 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] Apologies
I%60 should have been I%12 My previous request has been solved. From: Kermit Rose Date: 06/06/06 22:05:17 To: tutor@python.org Subject: end of line character seems to be invisible. why? I ran the program # inp = open("CMT_MCAID", "rb") # out = open("mcaid.txt", "w") # for I in range(1,1000): # if I I%60=== 0: On reflection, I realized that more than one character is being written with each character input, so I should have divided 60 by the number of characters output per character input. Thanks for all your assistance. Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Combo Box in Tkinter
Hi, Is there any Combo Box in Tkinter? I looked for it but only found list box. Might it be list box having any option to make itself as a combo box? Thanks, Phon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] end of line character seems to be invisible. why?
I ran the program #inp = open("CMT_MCAID", "rb") #out = open("mcaid.txt", "w") #for I in range(1,1000): #if I I%60=== 0: #out.write('\n') #ch = inp.read(1) #if not ch: break # EOF #k = ord(ch) # convert to integer #kl = k % 16 #kh = k / 16 #out.write('%d %d ' % (kh, kl)) #out.close() I added the lines #if I%60 == 0: #out.write('\n') because the output was one long line, and I wanted to be able to see the output when I opened the file with notepad. I expected that it would break the line at every 60 characters. It made no difference. The output file is still one long line. Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] bounced email
[Kermit Rose] > My last email to you bounced. > > > Why? > > From: [EMAIL PROTECTED] > Date: 06/06/06 20:30:49 > To: [EMAIL PROTECTED] > Subject: The results of your email commands > > > The results of your email command are provided below. Attached is your > original message. > > - Unprocessed: > ... Looks like you sent your original email to [EMAIL PROTECTED] instead of to the correct address (tutor@python.org). tutor-request is looking for Mailman commands in the body of your message, and can't make sense of what you wrote. Send messages to the right address and you shouldn't see this again. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] bounced email
Kermit Rose wrote: > > > My last email to you bounced. > > > Why? I don't know, it seems to be complaining about the HTML and missing some image? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I get Dos to recognize python command?
Kermit Rose wrote: > > I followed the model in > > http://www.byteofpython.info/read/source-file.html > > and saw following results. > > > C:\DavidKaremera\June2006\SAS>python med.py > 'python' is not recognized as an internal or external command, > operable program or batch file. > > > What do I do to make DOS recognize python as a command? You have to add the Python directory (C:\Python24) to your PATH environment variable. There are some directions here: http://www.python.org/doc/faq/windows.html#how-do-i-run-a-python-program-under-windows > > The link http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html > that you suggested > > shows information about the idle. > > I've used idle for development until now, but it has the annoyance > that I must close it and reopen it in order for it to import the changed > copy > of the program. I don't think you have to do that. If you open your file in an editing window you can run from there with Run / Run Module (F5). If you are importing into the shell window you can use Shell / Restart Shell to clear any imports, or use reload() to get a fresh copy. > > Besides, I already have one default module saved, and it would seem > complicated to have more than one. I don't know what you mean by this, what is a default module? Kent PS thanks for losing the graphics... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] bounced email
My last email to you bounced. Why? From: [EMAIL PROTECTED] Date: 06/06/06 20:30:49 To: [EMAIL PROTECTED] Subject: The results of your email commands The results of your email command are provided below. Attached is your original message. - Unprocessed: Why am I getting the following after my reply to you? -- next part -- An HTML attachment was scrubbed... URL: http://mail.python org/pipermail/tutor/attachments/20060606/798770c9/attachment.HTML -- next part -- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 1431 bytes Desc: not available Url : http://mail.python org/pipermail/tutor/attachments/20060606/798770c9/attachment-0001.jpe ** >>>>>> Message: 8 Date: Tue, 06 Jun 2006 19:50:01 -0400 From: Kent Johnson <[EMAIL PROTECTED]> Subject: Re: [Tutor] Tutor Digest, Vol 28, Issue 10 - Ignored: Cc: tutor@python.org There is no separate compile step, Python does that automatically. The details of running a program vary depending on your OS and how you create the file. Here are some directions: http://www.byteofpython.info/read/source-file.html http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html Thanks. I will study those links. >>>>>>> PS The standard on most public mailing lists is to send text email rather than HTML. I for one would appreciate it if you would lose the background graphics! * I know. It annoys me that my current email program sends HTML by default. I don't like the different sized letters that it makes. I did not know anything about background graphics. I will attempt to make this one message plain text, and keep on guard for making each message plain text. If I can't find the option to make it automatically plain text, I will need to develop the habit to change every message to plain text. Kermit < [EMAIL PROTECTED] > - Done. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How do I get Dos to recognize python command?
I followed the model in http://www.byteofpython.info/read/source-file.html and saw following results. C:\DavidKaremera\June2006\SAS>python med.py 'python' is not recognized as an internal or external command, operable program or batch file. What do I do to make DOS recognize python as a command? The link http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html that you suggested shows information about the idle. I've used idle for development until now, but it has the annoyance that I must close it and reopen it in order for it to import the changed copy of the program. Besides, I already have one default module saved, and it would seem complicated to have more than one. It would be simpler if I can get the dos prompt to work. Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 28, Issue 10
Kermit Rose wrote: > Thank you very much. It looks exactly what I wished to know. > > But now, I realize that I don't know how to invoke Python to compile and > execute the > program file. There is no separate compile step, Python does that automatically. The details of running a program vary depending on your OS and how you create the file. Here are some directions: http://www.byteofpython.info/read/source-file.html http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html > > I will be making rapid changes to the file, and recompiling over and > over again as > I change the program during my experimentation. Python is great for quick-turnaround incremental development. > > I guess that in the open command, the rb stands for read and something > else. > what is that something else? Binary. When a file is read in text mode, any line ending (CR, LF or CRLF) is converted to a newline (\n) character. Kent PS The standard on most public mailing lists is to send text email rather than HTML. I for one would appreciate it if you would lose the background graphics! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python application on a web page
Hi, I am so new to everything, I don't even know where to post my question... do bear... I made this Python calculator that will take an equation as an input and will display the computed curves on a shiny Tkinter interface Now, I'd like to make this application available on a public web page... and all I could come up with was this post Hints?!I'd also appreciate a link to a beginner forum Thanks Puzzled Me __Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 28, Issue 10
From: [EMAIL PROTECTED] Date: 06/06/06 12:31:25 To: tutor@python.org Subject: Tutor Digest, Vol 28, Issue 10 Message: 9 Date: Tue, 06 Jun 2006 12:21:51 -0400 From: Kent Johnson <[EMAIL PROTECTED]> Subject: Re: [Tutor] Reading characters from file in binary mode To: Python TutorHmm, my C++ is remarkably rusty but I think you want something like this: inp = open("CMT_MCAID", "rb") out = open("mcaid.txt", "w") for i in range(1000): ch = inp.read(1) if not ch: break # EOF k = ord(ch) # convert to integer kl = k % 16 kh = k / 16 out.write('%x %x ' % (kh, kl)) out.close() *** Thank you very much. It looks exactly what I wished to know. But now, I realize that I don't know how to invoke Python to compile and execute the program file. I will be making rapid changes to the file, and recompiling over and over again as I change the program during my experimentation. I guess that in the open command, the rb stands for read and something else. what is that something else? Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] elif
Øyvind, I know this isn't Python advice, but in general it seems as if setting up a cron job would be easier. If you don't know how, I could gladly help. - Sean On 6/6/06, Øyvind <[EMAIL PROTECTED]> wrote: > Hello. > > I need to make a program that does certain things every 5 minutes > mon-friday. I have started writing it like this: > > if strftime('%w') == 1: > if strftime('%M') % 5 == 0: > n.start() > > elif strftime('%w') == 2: > if strftime('%M') % 5 == 0: > n.start() > > > > This seems kind of a redundant way of writing the code. > > I haven't gotten any statement like this to work: > if strftime('%w') == 1 or 2 or 3: > or > for strftime('%w') in range(1,5): > > What would be a more efficient way of writing it without writing it > several times? > > Thanks in advance, > Øyvind > > > -- > This email has been scanned for viruses & spam by Decna as - www.decna.no > Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no > > ___ > 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] Reference a variable from a string whose value is the name of the variable
>data = [ ]>for i in xrange(1,101):> data = "" %i _n, f %i_v)) The function locals() will return a dictionary of variables in the current scope. This can then be used to reference variables by name. x=1 xname = 'x' print locals()['x'] print locals()[xname] This prints: 1 1 or for your example. data = [ ] for i in xrange(1,101): data = ""> Hope this helps. pjw ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Truly generic database API
Smith, Jeff wrote: > I'm looking for a truly generic database API in that the underlying DB > could be text, XML, SQL engine, etc. > > For instance, initially, the underlying database will probably be text > files but we may at some point want to move to a real database server or > possibly an XML file without having to recode all of the upper level > access. I don't know of any database API that spans even text files and a conventional database. The broadest Python database API I know of is the standard Python DB-API which give mostly portable access to a wide variety of databases. You will still have to deal with differences in data types, differing options in the API, and different SQL dialects but you can use a database as light as SQLite or as high-powered as Oracle or SQL Server or (insert your favorite high-end database here). http://www.python.org/dev/peps/pep-0249/ http://www.python.org/doc/topics/database/modules/ Object/relational layers like SQLObject and SQLAlchemy give you a higher-level API and more insulation from the variation between databases at the cost of a more limited selection of supported databases. http://www.sqlobject.org/ http://www.sqlalchemy.org/ I think to get the level of portability you are asking for you will have to write your own domain-specific data access module. This is a good idea anyway - you don't want to be spreading SQL code all over your program, for example. Your first implementation might be built on text files, maybe using the csv module. Later you can write new implementations for other back ends. If you write unit tests for the module it will ease the transition to a new back end greatly. I do question why you need such broad portability. Are you sure you can't start with something simple like SQLite with the option of MySQL, PostgreSQL or a commercial product later? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Truly generic database API
On Tuesday 06 June 2006 09:22, Smith, Jeff wrote: > I'm looking for a truly generic database API in that the underlying DB > could be text, XML, SQL engine, etc. > > For instance, initially, the underlying database will probably be text > files but we may at some point want to move to a real database server or > possibly an XML file without having to recode all of the upper level > access. > > Is anyone aware of such a thing? > > Thanks, > Jeff Jeff is looking for the holy grail. You might want to look at 'dabo' as a frame work. They currently support Postgres, MySQL, SQLite, Firebird, XML all with the same code base. John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Truly generic database API
I'm looking for a truly generic database API in that the underlying DB could be text, XML, SQL engine, etc. For instance, initially, the underlying database will probably be text files but we may at some point want to move to a real database server or possibly an XML file without having to recode all of the upper level access. Is anyone aware of such a thing? Thanks, Jeff ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading characters from file in binary mode
Kermit Rose wrote: > Hello. > > I wish to translate a SAS data file to text, and do not have the > professional > version of SAS to do so. > > I have the student version of SAS, and have translated the shortest of 4 SAS > data sets given. > > For the other 3, I wish to construct a python program to read the > characters in, one > at a time, translate them to hexadecimal, then figure out how the data > matches > the data dictionary that I have. > > I experimented with writing code in C++ to do this. > > My first experiment, in C++ is > > #include > #include > #define TRUE1 /* Define some handy constants */ > #define FALSE 0 /* Define some handy constants */ > ifstream f("CMT_MCAID",ios_base::binary); > ofstream G("mcaid.txt",ios_base::app); > char ch > int k > int kh,kl > int limit > limit = 1000 > > for (int I=1;I<= limit;I++) > > { > f >> ch; > k = ch; > kl = k%16; > kh = (k -kl)/16; > G << kh," ",kl," "; > } > > > How can I begin to experiment using python? What would be python code > equivalent > to the above C++ code? Hmm, my C++ is remarkably rusty but I think you want something like this: inp = open("CMT_MCAID", "rb") out = open("mcaid.txt", "w") for i in range(1000): ch = inp.read(1) if not ch: break # EOF k = ord(ch) # convert to integer kl = k % 16 kh = k / 16 out.write('%x %x ' % (kh, kl)) out.close() If your input file will fit in memory, there is no need to read a byte at a time, you could change the for / read /test to this: for ch in inp.read()[:1000]: If you can live without the space between the two digits you could use out.write('%02x' % k) With these two changes the entire loop becomes for ch in inp.read()[:1000]: out.write('%02x' % ord(ch)) If your input files are in a well-understood format, you might be interested in the struct module in the standard lib, which will unpack fixed format binary data, or pyconstruct which I think is a bit more flexible: http://pyconstruct.wikispaces.com/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt plz help
Siddhart: Kent is correct, I tried the os.system('clear') on my Debian linux box and the screen clears. Don't forget to use import os. Also, I 'm new to Python. Hello community. Ezra Taylor On 6/6/06, soumitr siddharth <[EMAIL PROTECTED]> wrote: > > how do i clear the scseer ?? > suppose i have two pages to display one > after the other ,how should i do it ? > > > > Yahoo! India Answers: Share what you know. Learn something new Click here > Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download > now > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > -- Ezra Taylor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Reading characters from file in binary mode
Hello. I wish to translate a SAS data file to text, and do not have the professional version of SAS to do so. I have the student version of SAS, and have translated the shortest of 4 SAS data sets given. For the other 3, I wish to construct a python program to read the characters in, one at a time, translate them to hexadecimal, then figure out how the data matches the data dictionary that I have. I experimented with writing code in C++ to do this. My first experiment, in C++ is #include #include #define TRUE 1 /* Define some handy constants */#define FALSE 0 /* Define some handy constants */ifstream f("CMT_MCAID",ios_base::binary);ofstream G("mcaid.txt",ios_base::app);char chint kint kh,klint limitlimit = 1000 for (int I=1;I<= limit;I++) {f >> ch;k = ch;kl = k%16;kh = (k -kl)/16;G << kh," ",kl," ";} How can I begin to experiment using python? What would be python code equivalent to the above C++ code? Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] elif
Øyvind wrote: > Hello. > > I need to make a program that does certain things every 5 minutes > mon-friday. I have started writing it like this: > > if strftime('%w') == 1: > if strftime('%M') % 5 == 0: > n.start() > > elif strftime('%w') == 2: > if strftime('%M') % 5 == 0: > n.start() > > > > This seems kind of a redundant way of writing the code. > > I haven't gotten any statement like this to work: > if strftime('%w') == 1 or 2 or 3: > or > for strftime('%w') in range(1,5): > > What would be a more efficient way of writing it without writing it > several times? First, I don't think the code you show is correct, the result of strftime() is a string so you should compare to a string: if strftime('%w') == '1': You have to repeat the entire condition, so you could write: if strftime('%w') == '1' or strftime('%w') == '2': This could be cleaned up with a temporary variable: dow = strftime('%w') if dow == '1' or dow == '2': You could also write this as if dow in ['1', '2']: Rather than (ab)using strftime() in this fashion, you might want to look at datetime.datetime. You could write now = datetime.datetime.now() if now.weekday() in [1, 2, 3] and now.minute % 5 == 0: Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt plz help
soumitr siddharth wrote: > how do i clear the scseer ?? > suppose i have two pages to display one > after the other ,how should i do it ? It depends on the OS and the type of display. For a console application on Windows, use os.system('cls') On Linux I think the corresponding command is os.system('clear') If you are using a GUI toolkit then tell us which one and a bit more details about what you want to do. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reference a variable from a string whose value is the name of the variable
Peter Jessop wrote: > Kent > > Thanks for your reply. > The structure is for sending form variables and values to a web server > with POST. > I am using urllib.urlencode which accepts a list or dictionary as argument. > > The idea is to look for airline tickets. > The airline I buy from only lets me search by data but I want to > automate the process by POSTing the form for a range of dates so that > effectively I can search by price not by date. > I will then parse the returned HTML using HTMLParser or BeautifulSoup. > > The form has a large number of variables and I just want to find a > tidy way to organise the information. It sounds like you should use a dictionary directly as your primary data structure. For data that is fixed just use a literal dictionary, for example args = dict(origin='SJO', destination='MHO') For dates, you presumably have some kind of loop to generate dates in a range, then insert them into the dict: for date in : args['date'] = date # fetch and parse the URL with args as the POST data Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt plz help
>> Try to rephrase that question. I don't think I was the only one not understanding what you are asking? Try to rephrase that response. I'm sure that you understand the double negative in the second sentence, but many who speak English as a second language (including, possibly, the original poster) will not! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] elif
Hello. I need to make a program that does certain things every 5 minutes mon-friday. I have started writing it like this: if strftime('%w') == 1: if strftime('%M') % 5 == 0: n.start() elif strftime('%w') == 2: if strftime('%M') % 5 == 0: n.start() This seems kind of a redundant way of writing the code. I haven't gotten any statement like this to work: if strftime('%w') == 1 or 2 or 3: or for strftime('%w') in range(1,5): What would be a more efficient way of writing it without writing it several times? Thanks in advance, Øyvind -- This email has been scanned for viruses & spam by Decna as - www.decna.no Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt plz help
Try to rephrase that question. I don't think I was the only one not understanding what you are asking? >how do i clear the scseer ?? >suppose i have two pages to display one >after the other ,how should i do it ? -- This email has been scanned for viruses & spam by Decna as - www.decna.no Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] FileDialogBox in Tkinter
> Yes, it helps and does what I want. I had read some also your > document, but > they don't talk deeply and widely about Tkinter. However, they are > good > resource to start. Yes, the GUI topic in my tutor only introduces some of the language and the most basic principles. I then leave you to read Fred's tutorial for more depth. But its one area where I keep toying with adding a new topic on "Advanced GUI programming" but I'm not really qualified to write that since I do very little GUI work! (For example I just realized the other day that I've never actually created a menu bar in any of my Tkinter programs to date! ;-) Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] FileDialogBox in Tkinter
On Tuesday 06 June 2006 14:49, you wrote: > > What to do in order to get FileDialogBox in Tkinter for using? > > > >>> import tkFileDialog > >>> res = tkFileDialog.asksaveasfilename(defaultextension=".txt") > > Does that help? > > > Where to find a complete reference of Tkinter? > > I assume you have checked the Tkinter section of the Python > web site? It points at several resources. > > Fred Lundh's site is the best online resource I think. > The most complete resource is Grayson's Book on Tkinter > published by Manning. > > Alan G Yes, it helps and does what I want. I had read some also your document, but they don't talk deeply and widely about Tkinter. However, they are good resource to start. Thanks. Phon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reference a variable from a string whose value is the name of the variable
Kent Thanks for your reply. The structure is for sending form variables and values to a web server with POST. I am using urllib.urlencode which accepts a list or dictionary as argument. The idea is to look for airline tickets. The airline I buy from only lets me search by data but I want to automate the process by POSTing the form for a range of dates so that effectively I can search by price not by date. I will then parse the returned HTML using HTMLParser or BeautifulSoup. The form has a large number of variables and I just want to find a tidy way to organise the information. Peter ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] FileDialogBox in Tkinter
> What to do in order to get FileDialogBox in Tkinter for using? >>> import tkFileDialog >>> res = tkFileDialog.asksaveasfilename(defaultextension=".txt") Does that help? > Where to find a complete reference of Tkinter? I assume you have checked the Tkinter section of the Python web site? It points at several resources. Fred Lundh's site is the best online resource I think. The most complete resource is Grayson's Book on Tkinter published by Manning. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor