[Tutor] Maybe advanced pexpect question?

2008-03-22 Thread Nathan McBride
I've used pexpect for a few projects and love it. Basically pexpect lets you spawn a program and interact with it from code like you yourself were running it in a console. How would you send the ctrl key? nomb ___ Tutor maillist - Tutor@python.org h

Re: [Tutor] More Converter

2008-03-22 Thread bob gailer
[EMAIL PROTECTED] wrote: > I am still in need of more help. Currently I am just trying to get one > conversion down, as then I can duplicate it. However I am not sure how to > make it Convert. Currently I am working with: > > # Converter > Original = raw_input("Insert inches, feet ") > There

Re: [Tutor] Libraries/Modules and how well you know them?

2008-03-22 Thread Kent Johnson
r dascenzo wrote: > What are the distinctions between a library and a module? Do people > frequently use the terms interchangeably in conversations, mailng > lists, and around the web? "module" is very specific, it is a single Python source file. A library is a collection of useful modules.

[Tutor] Libraries/Modules and how well you know them?

2008-03-22 Thread r dascenzo
Hello, As someone relatively new to programming, I've a few questions related to the Global Module Index: http://docs.python.org/modindex.html What are the distinctions between a library and a module? Do people frequently use the terms interchangeably in conversations, mailng lists, and ar

Re: [Tutor] append string

2008-03-22 Thread Dave Kuhlman
On Sat, Mar 22, 2008 at 09:46:58AM +0100, Andreas Kostyrka wrote: > > Basically, strings are immutable. If you need to append something to a > string, you need to construct a new string object with the new value. > > Now if you are using this to collect huge outputfiles in pieces, one of > the c

Re: [Tutor] x and y

2008-03-22 Thread Alan Gauld
"elis aeris" <[EMAIL PROTECTED]> wrote >I just need a way to key a list of tuples of 2 for referencing. > >> I have no idea what you mean by that, can you give a more >> specific example? OK, I have now read your discussion with Kent. Can i ask, have you tried going through any of the basic tu

Re: [Tutor] x and y

2008-03-22 Thread elis aeris
I just need a way to key a list of tuples of 2 for referencing. On Sat, Mar 22, 2008 at 3:48 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "elis aeris" <[EMAIL PROTECTED]> wrote > > > on a different note, also on lists, I need to save two values, x > > and y. > > > > list = { int, int > >

Re: [Tutor] x and y

2008-03-22 Thread Alan Gauld
"elis aeris" <[EMAIL PROTECTED]> wrote > on a different note, also on lists, I need to save two values, x > and y. > > list = { int, int > int, int > int, int > > but i am not sure of the syntax, is it possible to just read both > values > from the same entry in the list ?

Re: [Tutor] windows: pop up window

2008-03-22 Thread elis aeris
sweet, I love built in functions. thanks ! On Sat, Mar 22, 2008 at 3:15 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > elis aeris wrote: > > oh sorry, I should have been clear: > > > > how about just popping a prompt in the same window that is running the > > script? > > Sounds like you want raw

Re: [Tutor] windows: pop up window

2008-03-22 Thread Kent Johnson
elis aeris wrote: > oh sorry, I should have been clear: > > how about just popping a prompt in the same window that is running the > script? Sounds like you want raw_input(): http://docs.python.org/lib/built-in-funcs.html#l2h-59 Kent ___ Tutor mailli

Re: [Tutor] add to list

2008-03-22 Thread elis aeris
Another part of program takes care of that patternless stuff, only saving and retrieving for comparison is concerned for this part of the code. In [11]: d = { ('a', 'b'): '1', : ('c', 'd'): '2' } In [12]: In [12]: d['a', 'b'] Out[12]: '1' that does look like what I looking for, how does

[Tutor] x and y

2008-03-22 Thread elis aeris
on a different note, also on lists, I need to save two values, x and y. list = { int, int int, int int, int but i am not sure of the syntax, is it possible to just read both values from the same entry in the list ? ___ Tutor m

Re: [Tutor] add to list

2008-03-22 Thread Kent Johnson
elis aeris wrote: > there is no pattern in the numbers. Then how do you expect to create them automatically? I don't understand that part of the question. > two strings that look like "2.3.3.3.3.", youknow, str(int) + "." + > str(int) + "." and so forth > are presented and they equal to a va

Re: [Tutor] windows: pop up window

2008-03-22 Thread Kent Johnson
elis aeris wrote: > how about console window input? You want to "pop up" a console window? Usually if your program is running in a console you have a window already. Use raw_input() to get user input in the console. Kent > > On Sat, Mar 22, 2008 at 3:02 PM, Kent Johnson <[EMAIL PROTECTED] > <

Re: [Tutor] windows: pop up window

2008-03-22 Thread elis aeris
oh sorry, I should have been clear: how about just popping a prompt in the same window that is running the script? On Sat, Mar 22, 2008 at 3:09 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > elis aeris wrote: > > how about console window input? > > You want to "pop up" a console window? Usually

Re: [Tutor] suggestion on improving script

2008-03-22 Thread Kent Johnson
Norman Khine wrote: > I would like to alter this batch control so that I don't have to create > a new method everytime I need a new tab. > > For example, I would like to change t1, t2 ... t[n] depending on the tab > I am at. I don't really understand the question but I think maybe the tabs shou

Re: [Tutor] windows: pop up window

2008-03-22 Thread Kent Johnson
elis aeris wrote: > how do I pop up a window to ask user's input? Take a look at http://www.ferg.org/easygui/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] add to list

2008-03-22 Thread elis aeris
there is no pattern in the numbers. but don't worry about it, because all i am doing is this: two strings that look like "2.3.3.3.3.", youknow, str(int) + "." + str(int) + "." and so forth are presented and they equal to a value, which is the third string. in short, given the first two strings

Re: [Tutor] windows: pop up window

2008-03-22 Thread elis aeris
how about console window input? On Sat, Mar 22, 2008 at 3:02 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > elis aeris wrote: > > how do I pop up a window to ask user's input? > > Take a look at > http://www.ferg.org/easygui/ > > Kent > ___ Tutor maillis

Re: [Tutor] add to list

2008-03-22 Thread Kent Johnson
elis aeris wrote: > chat_window_char_definition = { "2.7.1." : "1", > "2.3.3.3.3." : "2", > "2.2.3.3.4." : "3", > "2.2.2.7.1." : "4", > "4.3.3.3.4." :

[Tutor] add to list

2008-03-22 Thread elis aeris
chat_window_char_definition = { "2.7.1." : "1", "2.3.3.3.3." : "2", "2.2.3.3.4." : "3", "2.2.2.7.1." : "4", "4.3.3.3.4." : "5",

[Tutor] windows: pop up window

2008-03-22 Thread elis aeris
how do I pop up a window to ask user's input? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Even More Converter!

2008-03-22 Thread Kent Johnson
Alan Gauld wrote: > Bear in mind that the use of commas is very much a > local thing. In some parts of the world periods are used > and a comma indicates a decimal point so > > 123,456 > > could be 123 thousand 456 or 123 point 456 depending > on where the reader is from. > > If that is impo

Re: [Tutor] Even More Converter!

2008-03-22 Thread Rolando Pereira
Alan Gauld wrote: > > If that is important you might need to investigate a locale specific > way of defining the seperator. I know Windows has hooks to get > it from the local settings but I'm not sure about *nix and I don't > know if Python has a generic way. > > This might not matter to you

Re: [Tutor] Even More Converter!

2008-03-22 Thread Alan Gauld
<[EMAIL PROTECTED]> wrote > When Python gives me the answer to my conversion, > is there a way to create it so every 3 numbers a > comma is inserted? Bear in mind that the use of commas is very much a local thing. In some parts of the world periods are used and a comma indicates a decimal poi

Re: [Tutor] Even More Converter!

2008-03-22 Thread Kepala Pening
sorry, I forgot that re search from the front of the string. import re putComma = lambda x: (','.join(re.findall("\d{1,3}", str(x)[::-1])))[::-1] print putComma(1234567) # 1,234,567 print putComma(12345678)# 12,345,678 print putComma(123456789) # 123,456,789 - Original Message -

Re: [Tutor] Even More Converter!

2008-03-22 Thread Dick Moores
How about: def intCommas(n):     """     inserts commas into integers. E.g. -12345678 -> -12,345,789     """     s = str(n)     sign = ''     if s[0] == '-':     sign = '-'     s = s[1:]     slen = len(s)     a = ''     for index in range(slen):     if index > 0 and index % 3 == slen

Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-22 Thread Alan Gauld
"maser" <[EMAIL PROTECTED]> wrote > I couldn't find a good resource explaining what > @classmethod and @staticmethod are in python and when, > how these could be used. I'm not sure which aspect of this is the problem Andreas has explained the strange @ syntax for a decorator however if its the c

Re: [Tutor] Even More Converter!

2008-03-22 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > When Python gives me the answer to my conversion, is there a way to create it > so every 3 numbers a comma is inserted? Django uses this function: def intcomma(value): """ Converts an integer to a string containing commas every three digits. For example,

Re: [Tutor] Even More Converter!

2008-03-22 Thread Rolando Pereira
Kepala Pening wrote: > import re > > num = 123456789 > > print ','.join(re.findall("\d{3}", str(num))) > > output: > 123,456,789 > [snip] The problem with that is that it cuts the digits in the end of the number, if they can't form a 3 digit value. Example: import re n = 1234 print ",".join

Re: [Tutor] Even More Converter!

2008-03-22 Thread bhaaluu
import re num = 12345678 print ','.join(re.findall("\d{3}", str(num))) output: 123,456 Where is the '78'? It looks like that solution inserts comma's from left to right instead of from right to left. -- b h a a l u u at g m a i l dot c o m "You assist an evil system most effectively by obeying

Re: [Tutor] Pseudo-functions and dicts

2008-03-22 Thread Kent Johnson
Shrutarshi Basu wrote: > There are two solutions I've thought about: > Have a function that takes in the sensor's name as a string and > responds accordingly. (which might be what I'll end up using) That is almost the same as using ordinary dict access, with slightly different syntax, e.g. senso

[Tutor] suggestion on improving script

2008-03-22 Thread Norman Khine
Hello, Please excuse me in advance if this post is long winded. I have the following nagging issue for which I have found a work around, but wanted a better solution. I am using jQuery to populate tabs with some data, such as news and jobs posts, as can be seen at http://uk.expert.travel In m

Re: [Tutor] Even More Converter!

2008-03-22 Thread Kepala Pening
import re num = 123456789 print ','.join(re.findall("\d{3}", str(num))) output: 123,456,789 - Original Message - From: [EMAIL PROTECTED] To: tutor@python.org Date: Fri, 21 Mar 2008 21:49:18 -0700 Subject: [Tutor] Even More Converter! It works perfectly, so I am sure my question will

Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-22 Thread Andreas Kostyrka
Well, it's classmethod/staticmethod in truth, @ is the decorator operator: def testdec(func): return {"funcobj": func} class Abc(object): @testdec def method(): pass assert isinstance(Abc.method, dict) Basically as you can see above, @X before a function definition takes the

Re: [Tutor] Pseudo-functions and dicts

2008-03-22 Thread Andreas Kostyrka
Well, there are basically two ways to go at it. If you want it at module level, you need to generate the functions: sensor = {'sens1': 200, 'sens2': 300} for key in sensor.keys(): def helper(keytofetch=key): return sensor[keytofetch] globals()[key] = helper print sens1() pri

Re: [Tutor] int to string

2008-03-22 Thread Andreas Kostyrka
Beside casting it with str(), you can also use a format string: assert "%d" % 10 == "10" assert "%5d" % 10 == " 10" assert "%05d" % 10 == "00010" In practice % supports a superset of what printf in C provides. Andreas Am Freitag, den 21.03.2008, 17:05 -0700 schrieb elis aeris: > how do I conv

Re: [Tutor] append string

2008-03-22 Thread Andreas Kostyrka
somestring = "ABC" somestring2 = somestring + "D" somestring2 += "EF" assert somestring2 == "ABCDEF" assert somestring == "ABC" assert id(somestring) != id(somestring2) Basically, strings are immutable. If you need to append something to a string, you need to construct a new string object with th