[Tutor] Fwd: Re: How do I display a picture?

2017-05-17 Thread Alan G via Tutor
n possible ways to "display a picture" depending on what you specifically want. -- Alan G Author of the Learn to Program web site [2]http://www.alan-g.me.uk/ [3]http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: [4]http:

Re: [Tutor] Writing decorators?

2016-07-05 Thread Alan G via Tutor
): ** ** def add_string(*args, **kwargs):** # in case f takes arguments ** ** ** ** return "decorated "+ str(f(*args,**kwargs)) ** ** return add_string Now we can apply that to a function @prepend def cube(n): return n*n*n cube(3) I'm biased beca

Re: [Tutor] Slack Token Invalid Syntax

2016-04-19 Thread Alan G
Apologies for top posting I blame the tablet! Malcolm, don't make us guess, show us how you put the quotes in and the error messages (in full). Alan g. Sent from my Fonepad Malcolm Boone wrote: So you are saying the right side should be a string, how do I do

Re: [Tutor] Why super does not work !

2011-01-17 Thread Alan G
shame since MI is where super() should be most useful... But in my experience MI in Python is definitely a place where explicit is better than implicit. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] call a def/class by reference

2005-09-29 Thread Alan G
resents the names to the user(as strings) in which case a mapping has to exist somewhere already. I'm curious as to how you are addressing those issues? Is this something that only developers will be using? How will the user know what names are possible? Alan G. _

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Alan G
ython tends to support vanilla CGI and to do PHP style coding you need add-ins like PSP(the first suchj and therefore the most basic) Either move up to a more powerful engine, like Zope, or adapt to CGI style coding. There are many web frameworks for Python but my needs are met by CGI at

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Alan G
>> can't use import because then Python would try to parse the HTML >> from the >> imported file. > > I thought PHP also parsed any html rendered through an included > file? It does but PHP 'understands' HTML

Re: [Tutor] Flattening multi-dimentional list

2005-09-29 Thread Alan G
ested lists rather than tuples but it should work for either) Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Alan's responce frustrated beginner

2005-09-29 Thread Alan G
approach is probably best IMHO (whether you parametereise the iterations and condition is optional, it just makes the function as geeric as possible...) HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Prevent "Coder's Remorse"?

2005-09-28 Thread Alan G
ass will ensure that all the values that should be there are indeed present. > Is there an object structure that will let updates to one instance > affect all instances? A class method is the traditional way of doing that. Get the init method to update a global (or class based)

Re: [Tutor] Multiple buttons, One callback (fwd)

2005-09-17 Thread Alan G
the new Win32 API and the older 16 bit Win 3 API. Why 'thunk' I do not know but the term seems to have stuck long after everyone stopped using Win32 thunks... Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld _

Re: [Tutor] Why won't it enter the quiz? (off topic)

2005-09-17 Thread Alan G
ers, it's in the individual's own interests to maximise their own input. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How do fix this error?

2005-09-17 Thread Alan G
y help here. See the Simple Sequences topic on my tutor for examples of string formatting. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Getting rid of the newline in file

2005-09-17 Thread Alan G
trip() + "Hi!" HTH, There is more on this topic in the file handling topic of my tutorial. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Why won't it enter the quiz? (off topic)

2005-09-17 Thread Alan G
such lists is fine, using code jointly developed is a legal quagmire. However given the nature of the code Nathan is producing and the prices he's charging I doubt if we are going to be contesting our share of his millions! It seems pretty harmless at this level. Alan G Author of the Le

Re: [Tutor] Will the following code ever exit?

2005-09-17 Thread Alan G
Then it might start to run although not necessarily correctly. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Multiple buttons, One callback

2005-09-16 Thread Alan G
calls the comon function passing the source id as an argument. The source Id is set up as a default parameter value in the lambda definition. HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Aschenputtel problem - Shorter is not better?

2005-09-16 Thread Alan G
subtle bugs (like my untested one-liner did!) then better to be slowly correct than rapidly wrong... :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Aschenputtel problem

2005-09-15 Thread Alan G
untion twice if you want to make the intent even more explicit... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Alan G
> for f, x in bunch_of_files, range(z): ... > Or maybe can I access the number of times the > loop has run? I think thats what enumerate does... >>> for x,y in enumerate([1,3,5]): ... print x,y ... 0 1 1 3 2 5 >>> Yep, looks like what you need. Alan G Author

Re: [Tutor] running scripts with windows

2005-09-15 Thread Alan G
> Cygwin (http://www.cygwin.com/) It gives you a bash shell in > Windows. Actually it gives you a whole Unix environment including X Windows and over 500 unix command line tools plus GNU C, sendmail, etc etc... Alan G. ___ Tutor maillist -

Re: [Tutor] running scripts with windows

2005-09-15 Thread Alan G
If you are a Unix head using windows run to the cygwin site and install the whole caboodle. You'll think you are back in Unix land... If thats impossible them open a DOS boc (aka Command Prompt) and type python foo.py Or even just double click the file in Windows explorer... A

Re: [Tutor] IDEs

2005-09-14 Thread Alan G
listed on the official plug in page. It was looking a tad daunting, now I don't need to. Excellent, thanks Kent. Alan G. PS Now off to find out what the heck 'Groovy' looks like! :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] IDEs

2005-09-14 Thread Alan G
better than IDLE, but I still prefer gvim and a command line prompt. Although I confess to firing up Pyhonwin occasionally to use it's debugger! Alan G. PS I'm playing with JSP at the moment and am very impressed with the open source NetBeans IDE. It would be nice if someon

Re: [Tutor] Another regular expression question

2005-09-14 Thread Alan G
> However is it normal that to parse a 2618 lines xml file > it takes 20-30 seconds or so? Only if you are running it on an original Palm Pilot! Seriously, I'd expect it to be more like 2-3 seconds. Something fishy there. Alan G. ___ Tut

Re: [Tutor] Another regular expression question

2005-09-14 Thread Alan G
and it's usually much easier to use a proper parser - such as beautiful soup. http://www.crummy.com/software/BeautifulSoup/ Is there any special reason why you are using a regex sledgehammer to crack this particular nut? Or is it just to gain expe

Re: [Tutor] Python as operating system?

2005-09-14 Thread Alan G
ll need a real OS underneath to talk to the hardware. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] (no subject)

2005-09-14 Thread Alan G
etter off with C or assembler, just be prepared to write a lot of code... HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] mamelauncher (fwd)

2005-09-14 Thread Alan G
lso can you post the error messages you get, its much easier for us to figure out where the errors are occuring if we see the full error text. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] socket question

2005-09-13 Thread Alan G
my file handling topic for some info and examples of usage: Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] mamelauncher

2005-09-12 Thread Alan G
lp but the system() call should work too, so I'd stick with it till we figure out whats happening. HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] hey i need some help here

2005-09-12 Thread Alan G
talled yet? You need to do that before you can use it. > When i insert python it says it is not recognizable as an internal > or external command. can somebody help me? The installer should set everything up OK, but try typing PATH at the OS prompt and see if Python appears anywhere in the

Re: [Tutor] mamelauncher

2005-09-09 Thread Alan G
lify your code(scrollable listboxes etc) 2) Your mailer seems to be adding extra lines, ie I assume the code isn't really double spaced? :-) So whats the specific problem? Oh yes - and what version of Python? Alan G. > I haven't added my error handling yet. > > Can anyone

Re: [Tutor] making a table

2005-09-09 Thread Alan G
format string (although in that case you might want a different format for the header) I also parameterised the function so you can specify the range of temperatures and the step size just for fun. :-) Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] python strings?

2005-09-08 Thread Alan G
atically calls str() on all its arguments so the programmer doesn't need to. An alternative way to solve your probnlem is to use format strings: print "Years = %s;\tPrincipal = %s" % (years,principal) HTH, Alan G Author of the Learn to Program web tut

Re: [Tutor] Making Applets

2005-09-07 Thread Alan G
pplescript But thats all I know (and even that is hearsay!) so I suspect you need to ask again on the MacPython programming list, they will know there what to do I'm sure. Sorry, but I suspect its just a tad too specialised a topic for the tutor list. Alan G. (Now someone will post

Re: [Tutor] Program to lock folders under win32

2005-09-04 Thread Alan G
h as expected from Microsoft its full of security holes by default!) If it's XP Pro you can add zipped folders too... I think there are registry hacks to turn on these facilities in XP Home too... You can access the hooks using the WSH objects and a COM interface such as the winall package.

Re: [Tutor] New GUI module

2005-09-04 Thread Alan G
is an enhancement of the older SpecTcl which I used when I did Tcl GUI programming. Its quite easy to use although in common with mamy such tools the code it produces is not particularly pretty. I've never tried IDE Studio... Alan G. Currently learning JSP with the aid of the NetBeans IDE..

[Tutor] New GUI module

2005-09-03 Thread Alan G
I haven't seen this mentioned on the list, but has anyone else noticed that v2.4 now includes the Tix GUI library in addition to Tkinter. Tix is a collection of more advanced Tk widgets (trees, tables etc) similar in many ways to PMW. Just in case its useful to anyone. A

Re: [Tutor] Print Output Location in Windows XP

2005-09-03 Thread Alan G
clicking the script file from a GUI where does stdout go? I've never tried that, being a command line junkie, but surely a similar prooblem ensues? Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld _

Re: [Tutor] FIREWALLS

2005-09-02 Thread Alan G
u post the error message? And if its not too long the code too? It saves us from guessing... :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Batch file to detect if Python is installed

2005-09-02 Thread Alan G
a little off topic... It does involve > Python > and programming... just not programming in Python. Seems relevant to me... BUT if you can be sure Windows Host Scripting is installed ands active that is much much easier to use... Alan G. ___ Tuto

Re: [Tutor] Need directions toward programming...

2005-09-01 Thread Alan G
get an idea of > the > whole aspect of language programming. Take time to explote other languages, Ruby, Smalltalk, Haskell and Lisp are all good alternative world-views. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld _

Re: [Tutor] How do use c/c++ methods in Python?

2005-08-29 Thread Alan G
ndows function the ctypes library may help, and may provide guidance on how to translate the struct. Can you clarify what you are trying to achieve? Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] New Tutorial topic

2005-08-28 Thread Alan G
dback is welcomed. Note that neither of these appears in the zip bundle as yet. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Working with files

2005-08-26 Thread Alan G
rwrites. You are better to insert the content into contents and then just write it all back to the file in one move. >file.write(contents[pos + len(name):]) >file.close() HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld _

Re: [Tutor] (no subject)

2005-08-25 Thread Alan G
gt;> s = u'\u8C01\u4ECA\u5929\u7A7F\u4EC0\u4E48' >>> list(s) [u'\u8c01', u'\u4eca', u'\u5929', u'\u7a7f', u'\u4ec0', u'\u4e48'] >>> What seemed to be the problem? Or am I missing something? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] (no subject)

2005-08-25 Thread Alan G
ice you wrote in binary mode but are reading in text mode. Does binary reading make a difference? Guessing, Alan G. PS. Anyone else notice how some topics seem to come up in bunches. We haven't had any questions involving binary files for months and this last week we've had at least

Re: [Tutor] checking substrings in strings

2005-08-25 Thread Alan G
> I would like to check if a certain word exists in a given string. > since I learned to love lists, I used > > if myword in mystring: > > ...didnt work. I have now resorted to > Which version of Python? >>> 'boo' in 'mybigbooboo' True &g

Re: [Tutor] Importing modules/classes

2005-08-24 Thread Alan G
' topic of my tutor. And more on OOP in the OOP topic - naturally! :-) Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] IndexError and appending to lists [Was: Re: Need Helpon Assignment]

2005-08-24 Thread Alan G
. That's all that mess is > for. The debug/test print statements are fine, I was only pointing out that one line did nothing, not the entire block. HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] IndexError and appending to lists [Was: Re: Need Helpon Assignment]

2005-08-24 Thread Alan G
t; print date[i], open[i], hi[i], lo[i], close[i], vol[i] > print T[1][2], T[0][0] > z = (hi[2] +lo[2])/2.0 > print z HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Remove a number from a string

2005-08-24 Thread Alan G
>> s = ' '.join(s.split()[1:]) > > or just > s = s.split(None, 1)[1] Neat, I hadn't noticed the maxsplit parameter before. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Remove a number from a string

2005-08-23 Thread Alan G
l do it: s = ' '.join(s.split()[1:]) If the numbes may form a more complex pattern then a regex would be better. Use the regex to find the end index and use a slice around the index. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Counting help

2005-08-23 Thread Alan G
: counts[name] = 1 print counts You could also use a list comprehension combined with the list count() method but I doubt if its much faster. HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Split a string into characters

2005-08-22 Thread Alan G
>How do I split a string like "Hans" into a list of characters > ['H','a','n','s']? >>> list('fred') ['f', 'r', 'e', 'd'] >>> HTH, Alan G Author of the Learn to

Re: [Tutor] reading excel and access files

2005-08-22 Thread Alan G
go (sorry, I can't > remember who). I found it very useful under Win32: > > http://www.microsoft.com/technet/scriptcenter/scripts/python/pyindex.mspx > Excellent! thanks for posting this, I hadn't seen it before. Alan G. ___ Tutor

Re: [Tutor] Will someone please tell me how to read this?

2005-08-22 Thread Alan G
ta represents. The first 4 bytes could be a 32 bit integer, or a short floating point value. Similary the 7p^ sequence could be three bytes from within an integer too. You really need to know whats being thrown at you down the socket otherwise you have very little hope of accurately decodi

Re: [Tutor] FW: How do you turn something into a number?

2005-08-22 Thread Alan G
e handling topic... (now corrected to fix a bug reported by a recent reader...) Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Network Tutorials

2005-08-22 Thread Alan G
ic, however it's short and accurate and quite good fun. Of course I may be a tad biased... http://www.btplc.com/thegroup/Networkstory/index.html Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] reading excel and access files

2005-08-22 Thread Alan G
nd involves lots of trial and error. OTOH If you have ever done it from VB you will know that already1 Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] nested loops

2005-08-22 Thread Alan G
> Is there any way more efficient for run a nested loop? > > -- > for a in list_a: if a in list_b: break Should help a bit, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Writing to text files

2005-08-22 Thread Alan G
ere I print out a restaurant menu with a daily updated header. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Importing serial module

2005-08-22 Thread Alan G
nately. Just read and write faitrly small blocks of data and it should seem to function concurrently. If you can't do that then threads are your next best option. Alternatively write two programs and join them via a common UI program using popen or subprocess... Alan g _

Re: [Tutor] Confused about embedding python in Html

2005-08-21 Thread Alan G
thon, serving up HTML pages with embedded JavaScript where you really need client side scripting. HTH, Alan G. ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Searching Sorted Lists

2005-08-20 Thread Alan G
ous problem indexing a list of even 1000 members. Premature optimisation is a dangerous trap. If you find you really have a problem then we can start to consider the options! Alan g ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Linux/Window Differences in Python?

2005-08-18 Thread Alan G
Python does have some nice features and is easier to read IMHO. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] need some help with ascii hex

2005-08-18 Thread Alan G
ord() > function, and to convert a number to hex notation you can use the > hex() function. And your advice was spot on so you see, you are a tutor! :-) Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld

Re: [Tutor] Need help with serial input

2005-08-18 Thread Alan G
getBytes(bytes) print bytes # data is list of 65, 67, 69 for b in bytes: print "0x%X" % b # represent number as hex You can use the struct module too, but it's a wee bit more complicated to use. An explanation of handling binary data can be found in the 'sidebar' in m

Re: [Tutor] Is there anyway to set how many numbers are used afterthe decimal in floating numbers?

2005-08-18 Thread Alan G
le currency conversion. This is discussed in the Bank account example in the OOP topic in my tutorial (the inevitable plug! :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is there anyway to set how many numbers are used after thedecimal in floating numbers?

2005-08-18 Thread Alan G
t always get what you expect: >>> round(1213.84567,2) 1213.84999 >>> But usually simply controlling the display witrh a format string is all you want to do. HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld

Re: [Tutor] Linux app question

2005-08-18 Thread Alan G
me the file, its just a nicety. All Unix scripts use this trick including shell scripts, awk, perl, tcl, ruby etc. It's been standard Unix practice for many years. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Float Addition

2005-08-18 Thread Alan G
s a mismatch between N_1 and the current position in the list. I think you are somehow reading one behind where you are writing. I'd look at the initialisation of that list. Another option might be to use -1 as the index to ensure you always use the last element: Dis_Tot = D

Re: [Tutor] Linux app question

2005-08-18 Thread Alan G
instead of python installer.py? THe usual unix shebang trick will work just fine. call your install script 'install' and put #! /bin/env/python as the first line. It should then run directly with no problems. Assuming of course that Python is already installed on th

Re: [Tutor] a little help

2005-08-17 Thread Alan G
Forwarding to tutor. > ok. yes i do use windows. how do i write my own encription?? > and yes i am going to use Tkinter You might like to take a look at this: http://docs.python.org/lib/crypto.html Alan G. ___ Tutor maillist - Tutor@python.or

Re: [Tutor] a little help

2005-08-17 Thread Alan G
d first then add the features of the final program one by one. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] IOError with fcntl.ioctl

2005-08-17 Thread Alan G
;m glad you found the answer and thanks for taking the time to post it. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Very simple question

2005-08-17 Thread Alan G
t because its too long or something you can use a \ character, like so: >>> print "Here is a split \ ... line" Here is a split line >>> HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld _

Re: [Tutor] Silly loop question

2005-08-16 Thread Alan G
ot;}",i) #other stuff happens changeIndex = nextRightBracket + 1 else: i += 1 > read Alan's tutorial again. *grin* Umm, well the section on branching does refer to the two loops and when each is most appropriate, so... :-) Alan G Author of the Learn to Program web t

Re: [Tutor] How can I make this run right?

2005-08-15 Thread Alan G
ef factorial(n): result = 1 for x in range(2,n+1): result *= x return result By avoiding while loops you avoid all the mess of trying to maintain the counter - one of the most common causes of errors in programming! For a different approach see the recursion topic in my tutor. HTH, Al

Re: [Tutor] How can I make this run right?

2005-08-15 Thread Alan G
nd how can I make it print out the correct > output? So give is a clue! What is it doing wrong? Is there an error message? What output did you expect? What did you get? Without that information we have to read the code and guess what you were trying to do. Then try to

Re: [Tutor] How can I make this run right?

2005-08-15 Thread Alan G
nd how can I make it print out the correct > output? So give is a clue! What is it doing wrong? Is there an error message? What output did you expect? What did you get? Without that information we have to read the code and guess what you were trying to do. Then try to

Re: [Tutor] Is it possible to...

2005-08-15 Thread Alan G
he cards as tuples or somesuch... Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] parsing through an output stream

2005-08-15 Thread Alan G
ad them you will need to use popen2 (Or the new subprocess module) to access stderr. I don't know for sure that mplayer is dping that but I'd say its a strong possibility. HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://ma

Re: [Tutor] re

2005-08-14 Thread Alan G
address is the 4th field and the time 7th. But it depends on what exactly you want to do with it. If you do want a basic intro to regex you can try my tutorial topic on them. It doesn't cover the deeper bits but gives the 30% I use 70% of the time... HTH, Alan G Author

Re: [Tutor] iterating in the same line

2005-08-14 Thread Alan G
ed loop: for line in someFile: for substring in s: if line.startswith(substring): # do something here Alternatively a regular exression match as suggested by others is probably faster. Alan G. ___ Tutor maillist - Tutor@python.org h

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-14 Thread Alan G
your own comparison function. Basically it will take two of your lists and return -1,0 or 1. Or you can use Python's own logic to help def cmplists(lst1,lst2): return cmp(lst1[2],lst2[2]) Now you can sort Quant by passing your function into sort... HTH, Alan G. _

Re: [Tutor] Invoking bash from within a python program

2005-08-14 Thread Alan G
dule documentation. How has it been in practice? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] iterating in the same line

2005-08-14 Thread Alan G
reduce that list to one element(which it already is!) by 'or'ing the elements. I can't even begin to guess from that what it is you are actually trying to do. Can you give us more explanation and maybe some sample data? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] pychecker: x is None or x == None

2005-08-13 Thread Alan G
y since the identity test (is) assumes that only one instance of None ever exists which could potentially change in some future exotic version of Python... You really are interested in the value of x not its identity. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] pattern matching is too slow

2005-08-12 Thread Alan G
should be faster, the second step faster still. Finally, lookaing at tyour regex you might be better using a simple string method - startswith() if temp.startswith("A"): That should be even faster still. HTH, Alan G Author of the Learn to Program web

Re: [Tutor] More problems with Learning Python example (fwd)

2005-08-12 Thread Alan G
t to be doing anything else at the time so the code was still in RAM or somesuch This is a good example of why timing tests must be done over many repetitions and averaged. Since you are running near the limit of recordability you might increase the number of

Re: [Tutor] More problems with Learning Python example

2005-08-12 Thread Alan G
gt; KeyError: I'm not quite sure what the second funcs loop is doing, but thats the reason for the key error. HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] changes made if IDLE not updating when application executed?

2005-08-11 Thread Alan G
type reload(myModule) at the >>> prompt before hitting F5? (I'm not sure whether this would have the result you see but its all I can think of!) Finally, what version of Python/IDLE and which OS? Alan G. ___ Tutor maillist - Tutor@python.o

Re: [Tutor] changes made if IDLE not updating when application executed?

2005-08-11 Thread Alan G
type reload(myModule) at the >>> prompt before hitting F5? (I'm not sure whether this would have the result you see but its all I can think of!) Finally, what version of Python/IDLE and which OS? Alan G. ___ Tutor maillist - Tutor@python.o

Re: [Tutor] Untainting CGI parameters

2005-08-11 Thread Alan G
> None, which has no attribute group. Ah yes! I forgot about the call to group(). I was just thinking if we got a None match. Ironic since it was me tagged the group call on in the first place! try/except it needs to be then... Alan G. ___ T

Re: [Tutor] Untainting CGI parameters

2005-08-11 Thread Alan G
group() or 'page' except KeyError: type = 'page' HTH Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Untainting CGI parameters

2005-08-10 Thread Alan G
alue) > type = match.group() > else: type = 'page' I Python "it's better to ask forgiveness than permission" so... try: type = re.search('\w+', parameters['type'].value).group() except KeyError: type

Re: [Tutor] SSH commands in Python on Linux

2005-08-10 Thread Alan G
and such. The ssh man pages explain it in fairly dense detail. > 2- If not, then is it possible to feed the SSH password > input with my Python script? Yes but you probably need the python version of expect module. Not part of the standard library but available o

Re: [Tutor] Customized endswith/startswith version

2005-08-10 Thread Alan G
f valid.startswith(['abc', '123', 'ff5'])] If the strings are all three chars you could do: [valid for valid in f if valid[:3] in ['abc', '123', 'ff5'] ] HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

  1   2   3   4   >