[Tutor] case insensitivity

2007-09-27 Thread Christopher Spears
I wrote a script that checks if two strings match. The script ignores case. #!/usr/bin/env python string_a = raw_input("Enter a string: ") string_b = raw_input("Enter another string: ") if cmp(string_a.lower(), string_b.lower()) == 0: print "The strings match!" else: print "The strings

Re: [Tutor] [tutor]Help needed to read Ascii file in wxPython

2007-09-27 Thread Michael Langford
While I would say wxPython in its fullblown glory is a little much for this mailing list, an easy to use toolkit and associated tutorials for it is not. I would suggest you use pythoncard, which is a toolkit that calls down to wxPython and is much faster to get going with: This will get you up and

Re: [Tutor] [tutor]Help needed to read Ascii file in wxPython

2007-09-27 Thread Varsha Purohit
Hi Kent, I am writing a program basically in python gui to open a file and display its content. File contains ascii data... here is an example of that. a text file having info like this ncols 4 nrows 4 xllcorner 392800 yllcorner 5376340 cellsize 55 NODATA_value -

Re: [Tutor] [tutor]Help needed to read Ascii file in wxPython

2007-09-27 Thread Kent Johnson
Varsha Purohit wrote: > Hello everyone, > I need a basic tutorial which can help me in reading or writing > ascii grid file What is an ascii grid file? Reading and writing text files should be covered in any Python tutorial, find one you like here: http://wiki.python.org/moin/Beginner

[Tutor] [tutor]Help needed to read Ascii file in wxPython

2007-09-27 Thread Varsha Purohit
Hello everyone, I need a basic tutorial which can help me in reading or writing ascii grid file thanks in advance, -- Varsha Purohit, Graduate Student, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to adjust a text file...

2007-09-27 Thread Kent Johnson
GTXY20 wrote: > Hi, > > I have a CSV file as follows: > > IDProducts > 1 a b c d > 1 a e > 2 a b c > 2 a > 3 b c > 3 a > 4 d > 5 a d > > I am trying to write a script that will take the CSV file and output > another text file as follows: > > ID Products >

Re: [Tutor] exec sintax error or bug?

2007-09-27 Thread paulino1
Citando Ian Witham <[EMAIL PROTECTED]>: > What version of Python arre you running Paulino? > > When I run your second snippet on 2.5 I get an error: > > >>> exp = "if i == 3 : continue" > >>> for i in range(5): > exec(exp) > print i, > > Traceback (most recent call last): >

Re: [Tutor] exec sintax error or bug?

2007-09-27 Thread Ian Witham
What version of Python arre you running Paulino? When I run your second snippet on 2.5 I get an error: >>> exp = "if i == 3 : continue" >>> for i in range(5): exec(exp) print i, Traceback (most recent call last): File "", line 2, in exec(exp) File "", line 1 SyntaxError: 'contin

Re: [Tutor] How to adjust a text file...

2007-09-27 Thread Ian Witham
> > > I am trying to write a script that will take the CSV file and output > another text file as follows: > > ID Products > 1a > 1b > 1c > 1d > 1a > 1e > > etc.. for all of the ID's essentially I need to create a single instance > for products for each ID - currently the

Re: [Tutor] How to speed up input/string parsing ...

2007-09-27 Thread Ian Witham
Check the SPOJ Python forums, the process is explained there. It's all about adding two lines of code at the beginning of your script. But I can't recall which two. Ian. On 9/28/07, Aditya Lal <[EMAIL PROTECTED]> wrote: > > Hello Kent, > I tried finding solution with using only strings but unfor

[Tutor] How to adjust a text file...

2007-09-27 Thread GTXY20
Hi, I have a CSV file as follows: IDProducts 1 a b c d 1 a e 2 a b c 2 a 3 b c 3 a 4 d 5 a d I am trying to write a script that will take the CSV file and output another text file as follows: ID Products 1a 1b 1c 1d 1a 1e etc.. for

Re: [Tutor] how to convert array into tuple

2007-09-27 Thread bhaaluu
Can you explain how this works? How would this be written in a "conventional" way? >>> foo = [1,2,3,4,5,6] >>> [(foo[i],foo[i+1]) for i in range(0,len(foo),2)] [(1, 2), (3, 4), (5, 6)] >>> foo = [1,2,3,4,5,6,7,8,9] >>> [(foo[i],foo[i+1]) for i in range(0,len(foo)-4,2)] [(1, 2), (3, 4), (5, 6)] Al

Re: [Tutor] How to speed up input/string parsing ...

2007-09-27 Thread Kent Johnson
Aditya Lal wrote: > I will start working on psyco ... though not sure what is it ? Google is your friend. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to speed up input/string parsing ...

2007-09-27 Thread Aditya Lal
Hello Kent, I tried finding solution with using only strings but unfortunately reversing a number has some interesting issues - For example: take following two numbers - 002000 002000 though the final answer is 4 - arriving at it using string is stripping '0' from both left and right of both numbe

Re: [Tutor] how to convert array into tuple

2007-09-27 Thread Kent Johnson
Noufal Ibrahim wrote: > This seems to work although I'd like comments from the more experienced > Pythonistas out there. > > >>> foo > [1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> [(foo[i],foo[i+1]) for i in range(0,len(foo)-2,2)] > [(1, 2), (3, 4), (5, 6), (7, 8)] This problem is a perennial favorite o

Re: [Tutor] how to convert array into tuple

2007-09-27 Thread Noufal Ibrahim
Fangwen Lu wrote: > Dear all- > > If I have an array array([1, 2, 3, 4, 5, 6]), and I want to get > ((1,2),(3,4),(5,6)). What should I do? This seems to work although I'd like comments from the more experienced Pythonistas out there. >>> foo [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> [(foo[i],foo[i+1]

Re: [Tutor] exec sintax error or bug?

2007-09-27 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hello! > > Why doesn't the second code snipet, work like the first? > for i in range(5): > ...if i == 3 : continue > ...print i, > ... > 0 1 2 4 > exp = "if i == 3 : continue" for i in range(5): > ...exec( exp ) > ...print i, > ... > Trac

Re: [Tutor] questions about tuples

2007-09-27 Thread Rikard Bosnjakovic
On 26/09/2007, Eric Brunson <[EMAIL PROTECTED]> wrote: > You can't use append() on a tuple, because a tuple is, by design, immutable. Yes, and that's why he appends to a list, then converts the list to a tuple. -- - Rikard - http://bos.hack.org/cv/ _

[Tutor] exec sintax error or bug?

2007-09-27 Thread paulino1
Hello! Why doesn't the second code snipet, work like the first? >>> for i in range(5): ...if i == 3 : continue ...print i, ... 0 1 2 4 >>> exp = "if i == 3 : continue" >>> for i in range(5): ...exec( exp ) ...print i, ... Traceback (most recent call last): File "", line 2, in

Re: [Tutor] do i have to import modules at the start of a file?

2007-09-27 Thread Michael Langford
In your particular situation, I've often used the "One Library, two executable" pattern. Put all the common functionality into one python module. Have one python file who's main brings up a GUI and one who brings up the admin cli interface, both of which that import the main library that does all

Re: [Tutor] do i have to import modules at the start of a file?

2007-09-27 Thread shawn bright
It's the second one, not all the modules will be available on the portable version. But the threads that require those modules will not be necessary on the portable version. I want to be able to go to any linux computer with GTK and mysqldb installed and check out my stuff from svn and run the admi

Re: [Tutor] ftp inside function

2007-09-27 Thread Kent Johnson
Nelson Kusuma wrote: > Dear Kent > > Thanks Kent, i made loop function to create directory > tree, and for the first login, i also want to make > inside function : > > def exeFtp(): > session=ftplib.FTP('myWorkstation','tes', 'tes') > direc="d:\TES" > direcFtp(direc) #function

Re: [Tutor] How to speed up input/string parsing ...

2007-09-27 Thread Kent Johnson
Aditya Lal wrote: > def rev(n) : > m = 0 > while n > 0 : > m = m*10 + n%10 > n = n/10 > return m I would try reversing the numbers as strings. s[::-1] will reverse a string s. > How do I improve the input reading or string parsing ? I know there > should be a better

[Tutor] How to speed up input/string parsing ...

2007-09-27 Thread Aditya Lal
Hi !! I was trying to solve SPOJ (www.spoj.pl) problems - ADDREV (add reversed numbers). My solution clocked 0.58 seconds in SPOJ's computer as compared to best time of 0.28. Interestingly my program spends 50% of its total execution time in reading/parsing the input. Following is the sample inpu