no doubt want to
use xor:
if not (a^b^c^d^e^f):
do it :-)
PS. The last works for primitive types but is not
intended to be a serious suggestion!!
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
If the code is slightly diffeent each time - although from
a quick look this doesn't seem to be the case here - you
can parameterise the function so you can pass in either the
changing values or some flag to indicate which variant you
need. It's all part of helping us to see the wood instead o
print ord{'Q'}
81
so '\x14' is the character, it should just work...
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauldHTH,
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
state it.
try: f = file()
except IOError: print 'file not'
If you do want to force an error to be raised you must use raise:
try: raise IOError
except IOError: print 'sure enough...'
See my tutorial topic on errors for
> Does anyone know of a Python debugger that will run under OSX 10.4?
> The Eric debugger was looked at, but it's highly unstable under
> Tiger. Thanks.
pdb should still work.
Alan g
___
Tutor maillist - Tutor@python.org
http://m
ow? Does your tutorial cover that (i don't remember it doing so)?
Two topics -- one on handling files the other on handling text.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
iterations, try it this
way:
heads,tails = 0,0
while heads+tails < 100:
coin = random.randrange(2)
if coin == 1: heads += 1
else coin == 2: tails += 1
run = raw_input('run or exit? ')
if run = 'run': continue
else: break
HTH,
Alan G.
_
ly they lose out in terms of
raw editing power.
I missed the original part of the post that prompted your decision,
but the quoted comment above suggests a new aopproach to debugging,
not necessarily a new debugger...
Alan G.
___
Tutor maillist - T
ead of returning them you store them in the object.
Or am I missing something?
It is possible to write true class methods but I'm not sure
this is the best place to use them.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
> I'm tryin compare a string with a value with style of
pattern-matching.
>
> string = 'i686'
>
> if string == glob.glob(i?86):
Use regular expressions and turn it around:
import re
s = 'i686'
ex = re.compile('i?86')
if ex.match(s): p
done from Acrobat using:
http://www.reportlab.org/rl_toolkit.html
to create the PDF and the /p flag in acrobat.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
access mechanism in Python other than seek()
You can't create fixed length records and navigate through them
as you can in some other languages. (you can of course use
format strings to fake this but its messier than true random
record access)
Alan G.
__
ript
to be too terrible, what kind of problems are you having?
PS
I couldn't reply to the original message because it had beebn
digitally signed. Please don't do that when posting to public mailing
lists folks! (Well, not if you want a reply!)
Alan G
Author of the Learn to Program web
run
a file from the command line like
python Hope.py
then __name__ is set to __main__
> but why would I want to do this if __name__ == '__main__':
So this line lets you create code that is executed when the file
is run from the command line but not wh
finished"
file and try exercising the functions classes one by one from
the >>> prompt. Finally insert print statements at suitable
points, and only after doing all of that try the debugger.
The best debugger of all is the one between your ears!
Alan G.
_
ing as you go. As soon as you
get a feature working put it in a function. It keeps the working code
and experimental stuff separate!
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
y the songs and
generate a random selection from the copy?
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
y and it sometimes
gives you some clues too. But the best bet is lots of write()
statements
IMHO.
Also the fact its one big file shouldn't be a problem. Provided you
make liberal use of functions to encapsulate the functionality and
keep those together in the head of the html the
the fine detail, but essentially the init
file often imports functions or classes that the package designer
wants to appear as top level(in the package as opposed to being in
a sub module). Also initialisation of package variables such as
constants can be done there.
HTH,
Alan G
Author of the
arameter to an attribute of the object, self.parent say.
Within the event handlers in the dialog you can now reference
Frame1 as self.parent.
HTH
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maill
r tried in Python but can you use select()?
I've used it in C for short duration intervals.
Just a thought.
Alan G
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
else: break
> ... to play a .wav music file. I tried w.play() but got an error
that
> module has no attribute 'play'.
Have you used dir(w) to see what it does offer? Even better what does
the documentation say? Have you tried help(w)?
HTH,
Alan G
Author of the Learn to Program web
ence. That way you can easily change the sequence,
reuse frames over again within the same wizard etc etc.
Hope that made sense,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist - Tutor@
n to the end.
> documentation is not always user-friendly for beginners!)
It assumes you are a beginner to the library but not to XML
and XML tutors generally assume you are new to XML not to http
or HTML. So you need to start at the beginning of web technology
and read your way up the tree.
tput = hex('%d' % (value))
WORKS
-
>>> hexoutput = hex(1234567890)
Are you trying to insert a hex representation of the number into a
string for printing? If so the easiest way is using string format
characters:
>>> print "In hex: %d = %X" % (42,42
control but that hardly counts!)
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
will simply print out the list of numbers from 0..255.
Do you have a purpose in mind or are you simply wanting to
observe chr() and ord() in action?
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tuto
if menu_choice == 1:
etc...
except NameError, TypeError:
# handle error here
break # only if you really need to..
print_menu()
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
lass MyClass: pass
I use that a lot.
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
Humans are intelligent
but slow, computers are stupid but fast. You have to break every
action down to the simplest level and get the sequence just right.
But once you do get this stupid box responding to your every whim
then it is a grat buzz!
Alan G.
___
Tut
> Rumor has it that Alan G may have mentioned these words:
>
> >Consuming 100% CPU won't make much difference, the CPU is running
all
> >the time anyway (when its not asleep).
>
> Not mine... my laptop runs a Crusoe processor, and it can
automatically
> scale it
> I have to write a function that will return the index of a line like
this:
>
> gvcdgvcgdvagTVTVTVTVTVTHUXHYGSXUHXSU
>
> where it first becomes capital letters.
I'd go with a regex search for that one...
Alan g.
___
Tuto
'%25s' intiger (in this
case 25) a variable?
Just create the string outsoide the formatting line:
fmtString = '%%ds' % width
s = fmtString % data
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
_
> >Just create the string outsoide the formatting line:
> >
> >fmtString = '%%ds' % width
>
> I think it should be '%%%ds' % width
Good catch Bob, you need the extra % to 'escape' the literal %
character.
Alan G.
__
> Is there a increment operator in python similar to c++
> like so "SomeVariable++"
No.
There is the shorthand += assignment but no ++
So x += 1
is the closest thing to x++
HTH,
Alan G.
___
Tutor maillist - Tutor
psueudocode becomes a very powerful techniqie
of seeing the "big picture" of your programs structure.
Once you get above 500-1000 lines pseudo code starts to break down
again - you need pseudo code for your pseudo code!! At this point
you need to start looking at higher level design techniques
ct the detailed design from the code using a simple text
filter like grep...
The ISO 9000 quality auditors love it...
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
e recommendation, but you do have to remember to ignore
the heavy use of recursion if you are working in Python. Otherwise
the basic concepts are very sound. And the formulistic approach to
designing a function is excellent.
Alan G.
___
Tutor m
loats.
I've Python
> 2.3.4.
Usually when that kind of thing happens to me I've accidentally used
a comma instead of a period.
Are you sure you don't have
self,_isNearMarker = ...
So Python sees it like
a,b = True
Just a thought,
Alan G.
__
ry
to use it directly?
Also checking the Win32 API it looks like:
uint32 GetOwner(
string User,
string Domain
);
expects a couple of parameters to hold the return values.
I dunno how Winall handles that but it may be worth investigating.
Alan G.
e
values in
> columns 1 and 5 were present as a pair more than once in the
original file.
My immediate answer would be to use awk.
However if that's not possible or desirable then look at the fileinput
module and the string.split function.
Alan G
_
essed'
> for all of the ids in the list, but can not figure out how
> to get this into a query to pass to the database.
What have you tried? What happened? It should just be a case
of using variable interpolation as you did for the Select.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
se we plan on growing our business.
Unless ADOpy is very slow I wouldn't expect a huge performance
increase since it will only be the compile phase, but if you
hit the query a lot then maybe 5-10%. You are more likely to
see the benefit in a drop CPU loading on the server.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
several levels) as desired.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
tu??? A linux distro maybe?
(*) I'm currently using SqlLite for my online tutorial on database
programming but the more I use it the less I like it! To the extent
that I might change to one of the others even though it means a
re-write of the tutorial topic...
Alan G.
__
the SQL DDL directly? In fact even
Visio
can do that.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
more accurate
one read the docs onslicing!)
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
I'll be surprised if there aren't
some at least - even if just demos with limited numbers of tables.
The commercial tools are so cheap(relatively) that we've never even
looked for freeware... Many of the UML tools (BOrland, iLogix,
Rational Rose etc) have free trial versions which
am cannot be coaxed to
write to
> the telnet session (window). I have attempted the telnetlib, but
the
> problem is that the telnet window does not show up.
Try pyexpect
I think you have to download it though.
Alan G.
___
Tutor maillist -
instead,
or if on Python 2.4 the new commands(?) module. While your approach
can be made to work it needs a fair amount of tweaking of environments
and the like. popen otr commands should simplify life significantly.
Alan G.
___
Tutor maillist - Tutor@pytho
tive = sys.stdin.isatty()
> > if isinteractive:
> > ...
> > else:
> > ...
> >
>
> tested and it works !
Aha! I knew about tty on Unix so I looked in the os module for it,
I never thought of it being a file method
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
if you had done:
>>> def myfunc(): print 'hello'
>>> myfunc
''
>>>
> s = repr( myFunc() )
> print s
Which assigns NOne to s and then prints the repr() of None
> 'None'
As it should.
What did you think it should do?
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
us as to why you would ever want to though?
It may be there's another solution to whatever the problem is.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
8) test it in in conjunction with the other classes it uses.
9) repeat 6-9 until all classes are built and tested (or enough to
implement some part of your application - a "use case").
10) build the driver program/fuinctoion/object that will pull it
all together into an application.
;t understand why I would want the modulus of anything.
Modulus (ie remainder part of an integer division) is very useful for
all sorts ofthings in programming, I'd be surprised if you never found
a use for it! :-)
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
rc
Within that file you define any settings you need including folder
locations.
Usually a combination of the above techniques is used, and a default
myapprc(no dot) held someplace like /etc/myapp used if no environment
variable is set or no valid local user file exists.
Alan G.
__
consistent inside a block, but
to
make it readable be consistent across all blocks!
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
n you post a message here it's worth including
the code - if it's not hundreds of lines long! And also a cut n paste
of the actual error message because, although they may not look
friendly initially, Python errors are actually very informative
once you know how to read them!
Take care,
A
>
> There must be others on this list using a newsreader and I would
> appreciate the list name used.
The trick is that you need to set up a new news account not the
standard feed your ISP provides. The news server required is
news.gmane.org
And the news group you need to loo
ings.
This is best illustrated by a character.
char c = '5'; // ascii value 53
int n;
n = (int)c; // type cast makes n hold 53
n = atoi(c) // type convert makes n hold 5
Sorry for splitting hairs but clearing the terminology might he
s. It is a new news service not available on your
ISP news server. It is not just a new group.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
s, but I coudn't understand them and make
them
> work...
You can use COM to script IE but navigating the mysteries of COM is
not
easy, especoially if you haven't done it before.
I suggest you look at urlib before going any further, but if you
really
need to have a r
27;Tuple' object has no attribute 'num_fields'
If results is a tuple then presumably the number of fields is just
the len() of the tuple?
HTH,
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
l takes var i from outside of
class A.
> Can somebody explain this ???
You only need to declare global if you are modifying data if you only
read it there is no need for explicit global statements.
Alan G.
___
Tutor maillist - Tutor@python.org
h
> >>Never mind. I found it - sys.exit()
You can do the same thing by
raise SystemExit
This avoids the need to import sys...
Alan G.
> >>
> >>Sorry to have wasted the bandwidth/time.
> >>--
> >
> >
> > This was in reference to a post ab
e
you start emacs. You can also bind it to a shortcut of your
own - after all this is emacs you can do anything! :-)
> I need to make shortcut for starting interpreter do you have any
idea.
record and save a macro
M-x apropos macro
is your friend...
it from his site.
The other ways are:
Unix/LInux/MacOS/BSD:
os.system('clear')
DOS/Windows console:
os.system('CLS')
Generic:
print '\n' * 100 # a 100 line screen...
Or you could find the control codes for your screen
and print them as
is also an O'Reilly
book on ncurses - the C version, and several online
tutorials for the C version too. The Python module is a
pretty straight translation of the C API to Python.)
Alan G.
>
> Python actually gets a lot of this
onsole-handbook.htm
My bad.
You are right. I've seen it used for windows console control
and was told it worked for "any console", I assumed that
included *nix but obviously not!
Its not as impressive a feat as I thought in that c
> but I don't understand why xemacs doesn't fix C-c C-c
Neither do I. BTW Do you know if this is specific to xemacs?
Or does it also apply to python mode in vanilla GNU emacs too?
I really should get around to loading python-mode and
trying it some d
da = [['1', '2 ', '3'], ['longer ', 'longer',
'sort']]
>>> mcw = [[len(r) for r in c] for c in tda]
>>> mcw
[[1, 2, 5], [11, 10, 4]]
>>> mcw = [max([len(r) for r in c]) for c in td
nix's "tee" utility works.
Use tee? It's designed for this kind of thing and there
are versions for Windoze too. I personally prefer to leave
this kind of logging as a user option rather than embed
it into my code.
Alan G.
___
lar, Access locks
by pages (default 2K?) which can mean a lot of data
rows being locked by a single update.
Make sure as a minimum that you are not locking on reads!
HTH,
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
etc/...
def menu1():
X=Canvas(root, width=200, height=200, bg="blue")
but2=Button(X,text="back",command=mainmenu)
but2.grid()
return X
The other option would e to pass main into menuN() as a
parameter and use that instead of X but I prefer the
approach ab
goodbye', goodbye)}
for m in menu.keys():
print "%s\t%s" % (m,menu[m][0])
cmd = raw_input('pick one ').upper()
menu[cmd][1]()
Does that help?
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
> What would be the most Pythonic way
THats always going to be subjective but...
> of printing (or extracting) every
> other element of a list?
I'd probably use range with a step of 2.
for index in range(0,len(mylist),2):
ptint mylist[index]
Alan G
Author of the Learn
JOhn,
> This is probably it:
> >>> arr = range(20)
> >>> arr[::2]
You are probably right, I forgot that slicing now
had a 3rd element... :-)
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
above but I assume
# that was just a posting error?
print cmd # for debug only
os.popen(cmd)
See if the line you are producing is what you think it should be.
Try typing it in at the shell and see if you get the same effect?
Without knowing the details of your data its hard to say much more.
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
splay of numbers etc etc.
Take a look in the Python docs for string formatting.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
rom
mysql_Conn()?
> Do I need to declare the cursor as a global variable?
No you need to return it from your function.
See the topic on modules and functions for more about
returning values from functions.
You might find you need to clear the cursor before using it too.
HTH,
Alan G
Auth
tance of another class?
Those are all different scenarios which could be described
by your paragraph above, which do you mean?
Or is it something different again?
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
__
.
You can also just copy the module file List.py into a folder
that's in your search path. That works too. But calling it List
is probably bad since Python already has Lists. Maybe you could
rename it something like NestedList? (Whatever that is!)
HTH,
Alan G.
hared - this echos C's use of 'static' variables.
Java and Object Pascal copied the name from C++ and now Python
seems to have adopted both names just to accomodate all tastes!
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
would be a better approach IMHO...
Neat, I understand, I think... Thanks Kent.
Alan G.
> >>> class Test(object):
> ... @staticmethod
> ... def static(): # no args
> ... print 'I have no clue how I was called'
> ... @classmethod
> ... def cls(cls):
ve it pick the pattern that describes it better from the
list.
Define 'better'.
Both regex describe it equally well, how is Python supposed to
know which one is 'better'? You have to tell it by ordering your
list according to your idea
ach subclass. i never thought of
using a try/except to add an attribute to subclasses based on cls.
I like it.
Thanks again Kent.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
t; For example, if I'm making a little noughts and crosses
> game and I print the board:
I'd use curses for this. Or better still a GUI.
> I've programs do this on the command line in Linux, so
> I assume it must be possible.
Curses
und 30 but with a distribution from
about 10 to over 70...
Be really keen and write a python program to collect the
answers parse out the ages and do the sums... :-)
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
> BTW, if you happen to need this while drawing only a single line,
the
> "\r" char gets you at the beginning of the current line !
And '\h' should delete back one char. Between the two techniques
you can control a single line, but not, sadly, a noughts
e counter - which may
be what you want under some circumstances, but it wouldn't
know which of the subclasses was calling it so couldn't
access their counters.
I think thats right!?
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Python wrapper won't work...
I suspect part of the problem is that the DOS terminal, even
with ANSI mode switched on, which is not common nowadays, is
still pretty limited compared to a VT100/200 terminal
in terms of cursor control.
Alan G.
__
Of course better still is a design document!
> Does anyone have any little "gamelets" like these,
There are several games on Useless Python, including
my guessing games framework (which is from my book) and
the heavily commented code is zipped up on Useless
(hmgui.zip). But most of the
must be a suitable bit of black magic that will
serve it up on a plate.
Doing some reading around the innards of classes should shed
light on it.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
t.
We did this with an Oracle Forms application about 12 years
ago when tabbed displays were very new and very sexy! :-)
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist - Tutor@p
program the same name as the module!
HTH,
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
rate over the list to create and pack/grid/place
each button.
HTH,
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
#x27;,'w')
prtfile.write(text)
prtfile.close()
os.system('lynx -p ./temp.html')
> Is this a simple task, or am I jumping into deep water? :)
> evangelinuxGNU Evangelist
Given your signature its probably not too difficult,
you can just send the basic text string to lpr
o fix the itch use that, if you want
to understand super() then that won't help and its over to
someone else! :-)
HTH,
Alan G
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
nd getch since you aren't prefixing
the names with the module?
Normally I'd expect to see
Keyln = msvcrt.getch()
> a=kbhit()
>
> Traceback (most recent call last):
> [snip]
> File "", line 0, in __main__
> NameError: name 'defined' is not defined
Th
except ValueError:
> print "Oops! That was no valid number. Try again..."
The except should align with the 'try' not the 'if'
Does that help?
Otherwise you need to give us a clue as to how it doesn't work.
Do you get an error message?
1 - 100 of 321 matches
Mail list logo