[Tutor] Tuples

2006-04-11 Thread Kaushal Shriyan
Hi All I am referring to http://www.ibiblio.org/obp/thinkCSpy/chap09.htm I did not understood the below Section at all :( 9.3 Tuples as return values Functions can return tuples as return values. For example, we could write a function that swaps two parameters: def swap(x, y): return y, x T

Re: [Tutor] dictionary datatype

2006-04-11 Thread Victor Bouffier
On Tue, 2006-04-11 at 22:37 -0500, Jason Massey wrote: > Works for me: > > >>> dict1 = { 0x2018:u'k', 0x2019:u'd'} > >>> n = 0x2018 > >>> print dict1[n] > k > >>> > > On 4/11/06, kakada <[EMAIL PROTECTED]> wrote: > Hello all, > > For example, I have a dictionary: >

Re: [Tutor] Extending a list within a list comprehension

2006-04-11 Thread Victor Bouffier
On Tue, 2006-04-11 at 22:17 -0400, Kent Johnson wrote: > Victor Bouffier wrote: > > > If the second element in each array passed as x is of variable length > > (that is, it has a different element count than three, in this case), > > the program needs to extend the list instead. Without list > > c

Re: [Tutor] dictionary datatype

2006-04-11 Thread Jason Massey
Works for me:>>> dict1 = { 0x2018:u'k', 0x2019:u'd'}>>> n = 0x2018>>> print dict1[n]k>>> On 4/11/06, kakada <[EMAIL PROTECTED]> wrote: Hello all,For example, I have a dictionary:dict1 = { 0x2018:u'k', 0x2019:u'd'}I assign:n = 0x2018print dict1[n]Then:KeyError: '0x2018'But I can call directly:print

[Tutor] dictionary datatype

2006-04-11 Thread kakada
Hello all, For example, I have a dictionary: dict1 = { 0x2018:u'k', 0x2019:u'd'} I assign: n = 0x2018 print dict1[n] Then: KeyError: '0x2018' But I can call directly: print dict1[0x2018] So, what is wrong with this? How can I solve it? Thx kakada _

Re: [Tutor] Question About Function Arguments and Returned Results

2006-04-11 Thread Kent Johnson
Richard Querin wrote: > > > On 4/11/06, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > > > There is no need to pass the class object in to the function, you can > create it in the function and return it. A class might be nice because > it gives names to th

Re: [Tutor] Question About Function Arguments and Returned Results

2006-04-11 Thread Richard Querin
On 4/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: There is no need to pass the class object in to the function, you cancreate it in the function and return it. A class might be nice becauseit gives names to the various values. A dict can also be used for this. Do what feels right :-)To be more sp

Re: [Tutor] Extending a list within a list comprehension

2006-04-11 Thread Kent Johnson
Victor Bouffier wrote: > If the second element in each array passed as x is of variable length > (that is, it has a different element count than three, in this case), > the program needs to extend the list instead. Without list > comprehensions, and the added capability to utilize and sized list a

[Tutor] encoding

2006-04-11 Thread kakada
Hi all, Does anybody know how to decode to Windows Latin ("ANSI") I know how to decode to utf-8: stringinput = stringinput.decode('utf-8') but while I use stringinput = stringinput.decode('ANSI') LookupError: unknown encoding: ANSI so what is the correct way to do it? Thanks and !Happy Khmer New

[Tutor] Question About Function Arguments and Returned Results

2006-04-11 Thread Richard Querin
I'm a relative newbie writing a function that carries out a bunch of calculations. The function requires about 4 or 5 numeric arguments as input but the data returned from the function call is about a dozen numbers in addition to a list of strings and a fairly long list of numbers (200+).  My quest

Re: [Tutor] Decorators

2006-04-11 Thread Victor Bouffier
On Tue, 2006-04-11 at 21:08 +0100, Alan Gauld wrote: > What was an easy to learn and use, ideal language > for medium sized to fairly large scripting projects is trying to turn > into > an all encompassing general purpose language which will be > increasingly difficult to use without falling down s

Re: [Tutor] Extending a list within a list comprehension

2006-04-11 Thread Victor Bouffier
On Tue, 2006-04-11 at 23:42 +0100, Alan Gauld wrote: > Hi Victor, > > I've gotta say that I much prefer the second version here. > > > temporal = [] > > temporal = [ [x[1][1], (x[0], description[x[0]], > >x[1][0], x[1][1], x[1][2] ) ] for x in elements ] > > temporal.sort() > > temporal.rever

[Tutor] [Fwd: Re: Extending a list within a list comprehension]

2006-04-11 Thread Victor Bouffier
I sent this to John directly. Posting to the list. Forwarded Message From: Victor Bouffier <[EMAIL PROTECTED]> To: John Fouhy <[EMAIL PROTECTED]> Subject: Re: [Tutor] Extending a list within a list comprehension Date: Tue, 11 Apr 2006 18:03:41 -0500 On Wed, 2006-04-12 at 10:29 +

Re: [Tutor] Extending a list within a list comprehension

2006-04-11 Thread Alan Gauld
Hi Victor, I've gotta say that I much prefer the second version here. > temporal = [] > temporal = [ [x[1][1], (x[0], description[x[0]], >x[1][0], x[1][1], x[1][2] ) ] for x in elements ] > temporal.sort() > temporal.reverse() # sort descending > elements = [ x[1] for x in temporal ]

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
>> Ah, but by that standard even assembler is syntactic sugar, now >> where are those hex codes and my keypunch? :-) > Only those of us who keyed the bin loader into a PDP-8 by toggling > switches, each representing one bit, can claim to be the most free of > syntactic sugar. Never used a PDP 8

Re: [Tutor] Extending a list within a list comprehension

2006-04-11 Thread John Fouhy
On 12/04/06, Victor Bouffier <[EMAIL PROTECTED]> wrote: > elements = [ > (codigo, [ cant, importe, porc]), > (codigo, [ cant, importe, porc]), > ... > ] > > And I want to sort descending on 'importe', which is x[1][1] for x in > elements. In python 2.4, you could achieve this by saying: elements.

[Tutor] Extending a list within a list comprehension

2006-04-11 Thread Victor Bouffier
Hi all, I have solved my problem, but would like to know if what I accomplished can be done with different data using list comprehensions. the list I want to sort has the following format: elements = [ (codigo, [ cant, importe, porc]), (codigo, [ cant, importe, porc]), ... ] Actual data is: In

Re: [Tutor] Decorators

2006-04-11 Thread Bob Gailer
Andrew D. Fant wrote: > [snip] try crossing lisp > with APL for a mathematically pure language that nobody can ever read. > One problem is that APL allowed unbalanced parentheses (as in )SAVE), whereas LISP does not. And of course there is the right-to-left vs left-to-right issue... I do mis

Re: [Tutor] Decorators

2006-04-11 Thread Andrew D. Fant
Alan Gauld wrote: >>Syntactic sugar *IS* a practical benefit. After all, every language above >>assember is syntactic sugar, and by your definition of no practical use. > > > Ah, but by that standard even assembler is syntactic sugar, now > where are those hex codes and my keypunch? :-) > > By p

Re: [Tutor] Tuple (Section 9.3)

2006-04-11 Thread Hugo González Monteverde
Hi Kaushal, I might have to do a little guessing and see what is not clear from the explanation. The whole point of returning a tuple as opposed to, say, returning a list, is the fact that tuples are NON mutable. That is, *apparently* you would not be returning a reference, but the values themse

Re: [Tutor] Decorators

2006-04-11 Thread Bob Gailer
Alan Gauld wrote: >> Syntactic sugar *IS* a practical benefit. After all, every language above >> assember is syntactic sugar, and by your definition of no practical use. >> > > Ah, but by that standard even assembler is syntactic sugar, now > where are those hex codes and my keypunch? :-) Onl

Re: [Tutor] for loops

2006-04-11 Thread Alan Gauld
>> >>Write a Python program to print out the following shape. >> >>You are expected to use two for loops (these must be nested) to solve >> this problem. >> >> output: >> * * * * * >> * * >> * * >> * * * * * > > That looks a lot like homework. I agree and very poo

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
>> I really don't like this proposal nor many of the others that currently >> exist to seemingly turn Python into Java and C++! If people want to > > FWIW there is enough perceived need for this (and adapters or protocols) > that it has been invented already two or three times, in PEAK (by Philip

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
> Syntactic sugar *IS* a practical benefit. After all, every language above > assember is syntactic sugar, and by your definition of no practical use. Ah, but by that standard even assembler is syntactic sugar, now where are those hex codes and my keypunch? :-) By practical use I mean adding func

Re: [Tutor] Database Connectivity

2006-04-11 Thread Mike Hansen
> Kaushal Shriyan wrote: > > Hi ALL > > > > How do i connect my python program to MySQL DB or Oracle DB > or can you > > please specify the URL which gives a detailed explanation on this. > > Basic connectivity is through modules that implement the > DB-API standard. Read the spec and find

Re: [Tutor] Scan Codes, Character Sets: Any Modules?

2006-04-11 Thread doug shawhan
No luck. I think I am missing something utterly basic, and completely unrelated to python. :-) I'll quit filling everyone's mailbox with cheese and move on to a terminal newsgroup for my future pesterances. Thanks for the help folks!On 4/11/06, doug shawhan <[EMAIL PROTECTED]> wrote: Oho! http://ww

Re: [Tutor] failing to learn python

2006-04-11 Thread Alan Gauld
> On Mon, Apr 10, 2006 at 04:20:37PM -0700, Danny Yoo wrote: >> http://gnosis.cx/TPiP/ > > I will read that and Alan's tutorial too (isn't that MS-Windows specific > ???) Nope, it usually mentions *nix workarounds etc Most of it is OS neutral. The OS and IPC topic are mainly Unix centric.

Re: [Tutor] Decorators

2006-04-11 Thread Kent Johnson
Alan Gauld wrote: >> proposal for dynamic function overloading: >> http://www.artima.com/weblogs/viewpost.jsp?thread=155514 > > I really don't like this proposal nor many of the others that currently > exist to seemingly turn Python into Java and C++! If people want to > code in the Java porridg

Re: [Tutor] failing to learn python

2006-04-11 Thread Python
On Tue, 2006-04-11 at 12:06 -0400, Payal Rathod wrote: > The reason I am disgrunted with Python is because lack of good > documentation. http://www.python.org/doc/ The Python Docs - possibly you missed this because of the plethora of links. The Library Reference used to have the tag line:

Re: [Tutor] Decorators

2006-04-11 Thread Michael
On Tuesday 11 April 2006 17:43, Alan Gauld wrote: > >> There is no practical use for decorators IMHO > > > > It's true that decorators are syntactic sugar and don't add any new > > functional capabilities to the language. > > Which is all I intended to imply. You have a different meaning of "pract

Re: [Tutor] comp.lang.python newsgroup

2006-04-11 Thread Danny Yoo
[taking [EMAIL PROTECTED] out of CC] Hi Kaushal, Please do not crosspost between [EMAIL PROTECTED] and [EMAIL PROTECTED] They are different mailing lists. > I went to a http://www.python.org/community/lists.html and found the > below newsgroup > > How do i use this news group and access th

Re: [Tutor] for loops

2006-04-11 Thread David Rock
* josip <[EMAIL PROTECTED]> [2006-04-11 09:13]: > I have problem with this question. > Can someone show me the code and than explain it? > > >>Write a Python program to print out the following shape. You are > expected to use two for loops (these must be nested) to solve this problem. >

Re: [Tutor] Scan Codes, Character Sets: Any Modules?

2006-04-11 Thread doug shawhan
Oho! http://www.wyse.com/service/support/kbase/Keydetl1.asp?Q=7&R=6 has the hex codes! Thanks! Perhaps this will fix what ails me.On 4/11/06, doug shawhan <[EMAIL PROTECTED]> wrote: Yeah, termca was were I looked first. The OpenBSD 3.8 termcap shows: :cr=^M:ct=\E0:dc=\EW:dl=\ER:do=^J:ds=\EF\r:e

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
>> There is no practical use for decorators IMHO > It's true that decorators are syntactic sugar and don't add any new > functional capabilities to the language. Which is all I intended to imply. > However this doesn't mean that there is no practical use for decorators. Nor did I mean that, af

Re: [Tutor] Scan Codes, Character Sets: Any Modules?

2006-04-11 Thread Alan Gauld
Hi Doug, > I am attempting to screen scrape SuperDOS, uses wyse 60 terminals > I must fall back to the old cntl-letter combos to get the cursor to behave Sounds like you need to find a tech spec for the Wyse 60. That should give you all of the Ctrl character combos to control the screen. If you

[Tutor] Webbrowser

2006-04-11 Thread Øyvind
Hello. I have recently discovered the Webbrowser module, and have started using it instead of just using IE thru win32com. But, have a few questions: 1) Is it possible to give it an adress, and if the browser gets a redirect to a different adress, I can override it? For example, I tell the browse

Re: [Tutor] Tuple (Section 9.3)

2006-04-11 Thread Hugo González Monteverde
Hi Kaushal, I might have to do a little guessing and see what is not clear from the explanation. The whole point of returning a tuple as opposed to, say, returning a list, is the fact that tuples are NON mutable. That is, *apparently* you would not be returning a reference, but the values the

[Tutor] for loops

2006-04-11 Thread josip
I have problem with this question. Can someone show me the code and than explain it?   >>Write a Python program to print out the following  shape. You are expected to use two for loops (these must be nested) to solve this problem.   output: * * * * * *  * *  * * * * * *

Re: [Tutor] failing to learn python

2006-04-11 Thread Payal Rathod
On Mon, Apr 10, 2006 at 04:20:37PM -0700, Danny Yoo wrote: > http://gnosis.cx/TPiP/ I will read that and Alan's tutorial too (isn't that MS-Windows specific ???) The reason I am disgrunted with Python is because lack of good documentation. Shell programming has great text and so do sed and

Re: [Tutor] unpack/regexp

2006-04-11 Thread doug shawhan
I always slice the string  in this sort of situation: s = "12345678901234567890123456789012 " t = s[:10],s[10:20],s[20:-1]     print t ('1234567890', '1234567890', '123456789012') One could always bracket it to make a list or whatever. Hope this helps! On 4/11/06, Paul Kraus <[EMAIL PROTECT

Re: [Tutor] unpack/regexp

2006-04-11 Thread Paul Kraus
> Python regex is a bit more verbose than Perl but you can do the same thing: > > In [2]: import re > > In [11]: m=re.match("(.{10})(.{10})(.{13})", line) > > In [13]: m.group(1, 2, 3) > Out[13]: ('1234567890', '1234567890', '123456789012 ') That work great. Regex tend to be "expensive" is there a

Re: [Tutor] Database Connectivity

2006-04-11 Thread Kent Johnson
Kaushal Shriyan wrote: > Hi ALL > > How do i connect my python program to MySQL DB or Oracle DB or can you > please specify the URL which gives a detailed explanation on this. Basic connectivity is through modules that implement the DB-API standard. Read the spec and find implementations here: h

Re: [Tutor] unpack/regexp

2006-04-11 Thread Kent Johnson
Paul Kraus wrote: > Ok sorry for the perl refernce but I can't figure out how to do this. > I have a fixed width text file i need to parse. > > so lets say I want an array to containt the pieces i need. > if the fields I want are lengths from left to right. > 10 10 13 > 123456789012345678901234567

Re: [Tutor] Database Connectivity

2006-04-11 Thread Ed Singleton
On 11/04/06, Kaushal Shriyan <[EMAIL PROTECTED]> wrote: > Hi ALL > > How do i connect my python program to MySQL DB or Oracle DB or can you > please specify the URL which gives a detailed explanation on this. SQLObject is your best bet: http://www.sqlobject.org/ If you're using MySQL, you will ne

[Tutor] Database Connectivity

2006-04-11 Thread Kaushal Shriyan
Hi ALL How do i connect my python program to MySQL DB or Oracle DB or can you please specify the URL which gives a detailed explanation on this. Thanks in Advance Regards Kaushal ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/l

[Tutor] unpack/regexp

2006-04-11 Thread Paul Kraus
Ok sorry for the perl refernce but I can't figure out how to do this. I have a fixed width text file i need to parse. so lets say I want an array to containt the pieces i need. if the fields I want are lengths from left to right. 10 10 13 12345678901234567890123456789012 I want to turn this into a

[Tutor] Scan Codes, Character Sets: Any Modules?

2006-04-11 Thread doug shawhan
The difficulty I have may or may not be something that may be easily handled with pyserial and some other mystery module.  I am attempting to screen scrape SuperDOS, an extremely closed system that uses wyse 60 terminals to communicate with a dos machine. I have not been able to communicate prope

Re: [Tutor] Emailid

2006-04-11 Thread Ed Singleton
On 11/04/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Kaushal Shriyan wrote: > > Hi All > > > > I am a ardent fan of python can I have email address for me > > I mean For example for me it would be > > > > [EMAIL PROTECTED] > > I don't know how you get a python.org mailing address but I'm sure it'

Re: [Tutor] comp.lang.python newsgroup

2006-04-11 Thread Kent Johnson
Kaushal Shriyan wrote: > Hi All > > I went to a http://www.python.org/community/lists.html and found the > below newsgroup > > How do i use this news group and access the information I need > > comp.lang.python newsgroup You can use Google groups http://groups.google.com/groups?group=comp.lang.

Re: [Tutor] Emailid

2006-04-11 Thread Kent Johnson
Kaushal Shriyan wrote: > Hi All > > I am a ardent fan of python can I have email address for me > I mean For example for me it would be > > [EMAIL PROTECTED] I don't know how you get a python.org mailing address but I'm sure it's not by asking here! Kent __

[Tutor] comp.lang.python newsgroup

2006-04-11 Thread Kaushal Shriyan
Hi All I went to a http://www.python.org/community/lists.html and found the below newsgroup How do i use this news group and access the information I need comp.lang.python newsgroup Thanks in Advance Regards Kaushal ___ Tutor maillist - Tutor@pyth

Re: [Tutor] Tuple

2006-04-11 Thread Alan Gauld
>>> tuple = ('A',) + tuple[1:] >>> tuple >('A', 'b', 'c', 'd', 'e') > > How does tuple = ('A',) + tuple[1:] this work > > Please explain me with an example OK, we will use the example you gave us! tuple is a bad name since Python has an internal type called tuple usd for converting a list

Re: [Tutor] input with default value option

2006-04-11 Thread Alan Gauld
>> With raw_input(), it allows to input value. Can it be used to input value >> with default value option? >> > response = raw_input("Enter some data:") > if not response: response = "default value" This is one of the few places where I do use the short-circuit evaluation trick: val = raw_input

[Tutor] Tuple (Section 9.3)

2006-04-11 Thread Kaushal Shriyan
Hi All I am reading this http://www.ibiblio.org/obp/thinkCSpy/chap09.htm and did not understood the Section 9.3 at all, Please explain me with an example so the idea become clear and understood 9.3 Tuples as return values Func

[Tutor] Emailid

2006-04-11 Thread Kaushal Shriyan
Hi All I am a ardent fan of python can I have email address for me I mean For example for me it would be [EMAIL PROTECTED] Regards Kaushal ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Decorators

2006-04-11 Thread Kent Johnson
Alan Gauld wrote: >> My problem, and this is after reading PEP 318 and other items found when I >> "Googled" for decorators, is that I can't figure out the practical use for > > There is no practical use for decorators IMHO > They are syntactic sugar added to the language to make some things > tha

Re: [Tutor] failing to learn python

2006-04-11 Thread Ed Singleton
On 10/04/06, Payal Rathod <[EMAIL PROTECTED]> wrote: > Hi, > I am trying to learn Python seriously for almost 2 months but have not > gotten far at all. Infact, it seems I have not understood even the basic > concepts itself. I know some shell, sed and awk programming. > I have tried reading Learni

Re: [Tutor] Tuple

2006-04-11 Thread Kaushal Shriyan
On 4/11/06, Noufal Ibrahim <[EMAIL PROTECTED]> wrote: > > On Tue, April 11, 2006 2:49 pm, Kaushal Shriyan wrote: > > Hi All > > > > I am referring to http://www.ibiblio.org/obp/thinkCSpy/chap09.htm > > > tuple = ('a', 'b', 'c', 'd', 'e') > tuple[0] > > 'a' > > > > > > And the slice operat

Re: [Tutor] Tuple

2006-04-11 Thread Noufal Ibrahim
On Tue, April 11, 2006 2:49 pm, Kaushal Shriyan wrote: > Hi All > > I am referring to http://www.ibiblio.org/obp/thinkCSpy/chap09.htm > tuple = ('a', 'b', 'c', 'd', 'e') tuple[0] > 'a' > > > And the slice operator selects a range of elements. > tuple[1:3] > ('b', 'c') > > > But if w

[Tutor] Tuple

2006-04-11 Thread Kaushal Shriyan
Hi All I am referring to http://www.ibiblio.org/obp/thinkCSpy/chap09.htm >>> tuple = ('a', 'b', 'c', 'd', 'e') >>> tuple[0] 'a' And the slice operator selects a range of elements. >>> tuple[1:3] ('b', 'c') But if we try to modify one of the elements of the tuple, we get a error: >>> tuple[0

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
> My problem, and this is after reading PEP 318 and other items found when I > "Googled" for decorators, is that I can't figure out the practical use for There is no practical use for decorators IMHO They are syntactic sugar added to the language to make some things that were already possible a li

Re: [Tutor] failing to learn python

2006-04-11 Thread Alan Gauld
>> What kind of real life problems are you interested in? You might like > > I am a parttime sys admin so I want system admin problem which usually I > do through shell scripts like parsing logs, generating reports, greping > with regexes etc. My tutor is specifdically targetted at computer power