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:
):
** ** 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
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
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:
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.
_
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
>> 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
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
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
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)
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
_
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
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
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
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
Then it might start to run although not necessarily correctly.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
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
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
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
> 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
> 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 -
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
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
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
> 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
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
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
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
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
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
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
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
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
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
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
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
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.
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..
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
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
_
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
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
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
_
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
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
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
_
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
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
> 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
' 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
. 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
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
>> 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
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
: 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
>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
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
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
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
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
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
> 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
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
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
_
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
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
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
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
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
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
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
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
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
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
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
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
;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
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
_
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
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
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
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
he cards as tuples or somesuch...
Alan G
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
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
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
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
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.
_
dule documentation.
How has it been in practice?
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
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
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
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
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
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
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
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
> 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
group() or
'page'
except KeyError:
type = 'page'
HTH
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
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
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
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 - 100 of 321 matches
Mail list logo