"Daniele" wrote
* I cant get a code to work for this bottom half, Can anyone
help me
OK, since we've started giving solutions...
Hi Jared, try this:
for i in range(-10,11):
print '*'*(11-abs(i))
This is simpler using
for n in range (10,0,-1):
print '*' * n
HTH,
--
Alan
"Daniele" wrote
for i in range(-10,11):
print '*'*(11-abs(i))
Apologies, this is actually more powerful than my solution which
only addressed the immediate concern of printing decreasing
lines. This of course covers both sides of the triangle.
It was only when I thought that it should
> I am sorry , some how how i missed it . code you pls explain this.
> for i in range(-10,11):
> print '*'*(11-abs(i))
OK,
the range() function returns a list of numbers from -10 to +10.
the for loop assigns i to each value in turn
The print statement prints out the asterisk repeated (11-
Hi,
That was an interesting post, but I'm not sure what you want help with.
Is it the word splitting?
Is it writing the POS tagger?
Is it comparing tthe POS tagger to the standard?
Or all of these?
Alan G.
"Emad Nawfal (عماد نوفل)" wrote in message
news:652641e90903240835o610d013dsd6a81f4675c4
"T" wrote
I'm working on Paper, Rock, Scissors in Python.
I need to make it a loop, and test the values
(1, 2, 3, /Rock/Paper/Scissors) yet, but i'm kind
of stuck. Could you help me?
What exactly puzzles you? You know you need
a loop so you presumably realize that you need
to repeat some
"Coco Yeh" wrote
I have problem using windmill with a ssl website (https).
The browser does not go to the website, showing a tutor page instead.
How can I resolve this?
My initial response was to say "ask on a windmill list,"
but, not having heard of windmill, I googled and discovered
"amit sethi" wrote
what are the ways in which i can use C in python programs .
You can't use C directly what you can do is access libraries written in C.
In fact quite a few of the standard libraries are written that way.
So it depends what you want to do.
If you have C source code that yo
"Wayne Watson" wrote
My e-mail address is valid. Any ideas? I've compacted related Trash
folders, etc
It should be news.gmane.org... Or is that just a typo?
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinf
"Bala subramanian" wrote
for files in flist:
handle=open(flist).readlines()
print>>out, handle
print>>out, handle[1:]
Should do it? You might need to handle line endings though...
Alan G.
___
Tutor maillist - Tutor@python.org
http:/
"Wayne Watson" wrote
My e-mail address is valid. Any ideas? I've compacted related Trash
folders, etc
It should be news.gmane.org... Or is that just a typo?
In that case you probably need to tell us more.
Can you read the group OK in TBird?
What other settings are you using?
I can'
Use '\n'.join(handle[1:])
It will create a string from your list with newline as separator.
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
From: Bala subramanian
To: Alan Gauld
Sent: Thursday, 26 March, 2009 6:11:59
"NBarnes" wrote
Fortress). It seems like Python would be a good choice for such a
relatively simple project, and I've been wanting to learn Python.
seems reasonable), but I understand that we've since moved on to
Python 2.6? And that Python 3.0 is out? Is 3.0 mature enough to
support this
"Kent Johnson" wrote
On Thu, Mar 26, 2009 at 2:58 PM, ALAN GAULD
wrote:
Use '\n'.join(handle[1:])
It will create a string from your list with newline as separator.
The lines from readlines() include the newlines already.
Ah, OK, I couldn't remember if readlines
Try packing the frame to the left and set it to expand.
HTH, Going on vacation
Bye
Alan G.
"Wayne Watson" wrote in message
news:49cd0d40.5090...@sbcglobal.net...
Signature.htmlThe code below is clearly not shifting the contents of the
frame to the left. It's supposed to look like
"james carnell" wrote
example:
x row = 25 : col = 10
x row = 26 : col = 10.3
x row = 27 : col = 10.6
0x000 row = 28 : col = 11
for col in range(10,12, 0.3): #<- Crash Bang doesn't work 0.3 = zero =
infinite loop?
If you know the limits (rather than their being variables) you c
"W W" wrote
Good news... I got it!
Here's something that's often a good idea when debugging overlapping
layouts
(especially when you didn't design the parent!) - use different
backgrounds!
Yes, or for Frames use a relief value to see where the frame bounds are.
Here's my changes (also f
"Wayne Watson" wrote
I plainly had a copy of the Subject pdf in the past. ...
. A search of my PC shows nothing.
Try this:
http://www.ezgoal.com/house/final.asp?software=201967
Its what I use to produce the PDF version of my website.
The tool presents a web site within an app that allows
"Wayne Watson" wrote
I get the feeling, particularly with Tkinter and PIL, that I'm dealing
with antiquated tools, and documentation.
They are both quite old and therefore quite stable. They do what
they do well and don't need to change very often. That is a
Good Thing in that they are reli
"Wayne Watson" wrote
> The grid is a perfectly good layout manager but like all such
> tools it works in a particular way and has lots of options. Some
To me grid looks like simple arithmetic, +, -, * and /, but someone
left out the description (in a fictitious book on arithmetic) of "/
"(
"Wayne Watson" wrote
manipulation - actually creating and editing GIF/JPEG images etc
The interaction stuff you need to do using the GUI toolkit.
The GUI toolkit, Pmw, Tkinter?
Yes exactly.
Or wxPython or PyGtK or whatever, they will all provide a canvas
type widget which you can progr
"Chris Castillo" wrote
I need some help converting the fractional (right side of the decimal) to
base 10.
I have this but it doesn't work
Frankly, based on your algorithm, I'm not sure what exactly you want
to do but taking the above statement as a starting point
I'd convert the fractional
"Benjamin Serrato" wrote
formatting of my zip arguments is incorrect. Since I am unsure how to
communicate best so I will show the code, the error message, and what I
believe is happening.
Thats pretty close to communicating the best way! :-)
zip_command = zipfile.ZipFile(target, 'w').writ
"Chris Castillo" wrote
well i want to use a for loop to work from the right most digit to the
left
most digit at a negative 1 increment. For each digit i want to divide it
by
1/base and add the next digit. Then I need to take that sum and multiply
it
by 1/b to get the decimal equivalent
so
"Wayne Watson" wrote
Personally, I'd rather see these mail lists turn into forums formats.
Web forums are far less useful than mailing lists for technical groups.
They require internet access and a browser to read them.
Many require a graphical browser so don't work in text mode
terminals.
"Chris Lee" wrote
Before I tell you about my problems, I ask for your consideration
as I am a newbie at python...
That's OK, its what the tutor list is for! :-)
I was having problems as I tried to open another program
within a program (both programs are Tkinter UIs)
OK, That can be trick
"Sifis Sifakis" wrote
I'm a student in Applied Informatics and i need to make a project in
Python.
More specificaly,i have to create a simple online bookstore using Python.
We don;t do homework for you but we are happy to help with pointers
and bug fixing.
Could you also send me some sampl
"Pirritano, Matthew" wrote
I am a total newbie. I have a very large file > 4GB that I need to
convert from Unicode to plain text. I used to just use dos when the file
was < 4GB but it no longer seems to work. Can anyone point me to some
python code that might perform this function?
When you s
"Wayne Watson" wrote
I offered in that thread that it might be useful to allow people to
post images and videos. They can sometimes be very useful
One response was that such sites are generally available.
Indeed and posting big images or any size video in a mailing list
would be very
I'm currently updating my tutorial to cover Python V3.
I thought it miight be good to include some stuff on EasyGUI for the
user input topic and on checking the web site it said Easygui was
compatible with Python v3. However after downloading and installing
I get a "No module named StringIO" e
"Alan Gauld" wrote
user input topic and on checking the web site it said Easygui was
compatible with Python v3. However after downloading and installing
I get a "No module named StringIO" error under Python v3.
OK, Not much digging required.
StringIO has moved to
.
At the most basic level you can use the socket module and do it all
from scratch, but if its a higher lervel protocol there may be higher level
modules already written that will help.
We need to know a lot more about the problem and the
environment - what kind of computer/OS etc.
--
Alan Gauld
hought about using regular expressions to pull the data I need.
You probably don;t need regex, but it depends on what exactly
you want to filter/extract.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
__
on that in a few
minures...
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
an then inspect the event
to find out which key was pressed, where the mouse moved to, etc
As I say thats just a slightly different way to think about objects and OOP
I personally find it very helpful, you may too. If not, don't worry about
it! :-)
--
and have a registry setting or config file or
environment variable specify where that directory is. You can
then read the config data at startup and use that to create
the path for the image.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_
> That's a great idea Mr. Gauld!
> But I have no idea how to do that...
> can you maybe write a small example for a newb like me?? pretty please with
> cheese on top??
> > > base = pic(file="base.gif")
> > >
> > > Now, I'm just wondering... for the "base.gif" part, would it be better
> > > to
"Dave Angel" wrote
To use a relative path base = pic(file=root+"/base.gif")
I would get 'root' this way, rather than requiring anything to be set up
by the install (registry, environment vars, config):
Good idea, I forgot that in Python you can find the full path that way.
Too used to w
value2 = randrange(1,7)
die2.setValue(value2)
value3= randrange(1,7)
die3.setValue(value3)
value4 = randrange(1,7)
die4.setValue(value4)
value5 = randrange(1,7)
die5.setValue(value5)
rlist = [value1,value2,value3,value4,
lly,
if on Unix, you should probably respect the EDITOR or VISUAL
environment variables since they reflect the users editor
preferences so the code should look like:
ed = os.getenv('EDITOR')
vi = os.getenv('VISUAL')
editor = vi or ed
if editor:
subprocess.Popen().call([editor,
"Dominique" wrote
I tried several other ways without any success:
subprocess.Popen(args = ["notepad++.exe", filename])
subprocess.Popen(args = ["C:\Program Files\Notepad++\notepad++.exe",
filename])
I wonder if it is due to the location of the softwares.
In a way. I think it's because you
"Wayne Watson" wrote
raw_image=raw_file.read()
One more question, when I tried (no 'wb') read(size=307200),
why di read balk at size, syntactically.
It doesn't balk at the size syntactically it finds what it thinks is
an End Of file character code in the data and stops reading.
Tha
"Wayne Watson" wrote
Possibly contact Steve Ferg?
Yes I did that and Steve has included my fix in the latest version.
He also kindly gave a plug to my tutorial :-)
I've now included a section on EasyGui in my "Talking to the User"
topic in the Python v3 version.
--
Alan G
Author of the Le
a graphic then generating the graphic as an image and
loading the image into the canvas might work better.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.py
n what the bytes actually represent.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
he
above from a loop in Python, and generated hex equivalents in the last
list.
It might help to see those loops because it might
explain the reasoning behind the apparently arbitrary
decisions.
Can numpy do this simply without resorting to loops?
Can't
set of GUI
programming more than it is specifically Pythonic.
The events themselves tend to be GUI specific - Windows being
slightly different to X Windows or MacOS for example.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.al
ou can use a higher
level module if one is available.
Raw sockets should only be needed if you are doing bespoke
communications between processes.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist
"Access denied!" Is that mean my script has no power to
delete
it?
More likely the user running the script does not have the correct
access permissions or someone else is using the repository at
the time thus locking it.
HTH,
--
Alan Gauld
Author of the Learn to Program we
ic for you.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
hod passing the name
and value so that the A default never gets used in B instances.
The OOP topic in my tutor describes this in more detail.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor mail
setdefault() was effectively instantaneous.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
concurrent sequential machines and state automata
theory and any text book on formal simulation techniques.
HTH
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.o
fficulties figuring what it is all about.
If you can show us an example and tell us what you don't
understand we might be able to give more specific
answers. Also please tell us which version of Python
you are using and which Operating System.
--
Alan Gauld
Author of the Lear
a variable name etc
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ut the direct
import makes for shorter coding, especially if you use the
function a lot.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ame = tableName
Which you do here!
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
"Emile van Sebille" wrote
Redundant, yes; syntax error, no. IIRC, semi-colons are optional line
terminators.
statement terminators I think. ie you can have several statements
on a line by separating with semicolons:
x=5; print x+2
7
Alan G
__
> In general, importing a package does not give access to members of a
> sub-package. You have to explicitly import the subpackage. For
> example,
>
> In [1]: import xml
> In [2]: xml.dom.Node
> ---
> AttributeError
ou
can import them and read the doctrings wiothout actually opening
the code in an editor (which you would need to do for normal
comments)
So they are not essential but they do have a very real use
beyond simple comments..
I say a bit more about docstrings in my tutorial topic
"Ad
x27;m not
sure if it works for other platforms.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
iables separated by newlines or just put all 3 commands
on a sinlgle line separated by semicolons:
print 5; print 6; print 7
5
6
7
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tu
lthough well on the
way now...
The freenetpages site is scheduled to close and
they are not allowing any updates, hence the move
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@
he other
says 'chic', just as you told it to. In every other respect your
code is identical so the output is identical. Python just does
what you tell it to, it is not actually intelligent, it just interprets
the commands you give it.
HTH,
--
Alan Gauld
Author of the Learn to Pr
"wesley chun" wrote
i'm trying to collate a complete newbie-to-programming list of
resources and was wondering if you could help me fill in the holes...
thx in advance!
What about the free (and even the pay for) videos on the
ShowMeDo site. I thought they were pretty good especially for
sh
split(',')]
newlist
[1, 2, 3, 4, 5]
Provided your original data doesn't have commas to start with
it should work, I think... And the data needs to be pretty
homogenous to allow a single conversion function.
--
Alan Gauld
Author of the
or in a design document for the bigger application
level how!
Those are my personal rules of thumb.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
nction!
Again second call to the same function
valuse outside the function: [10, 20, 30]
values inside this function: [10, 20, 30]
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
could put the for loop inside the Student
class __init__ method so it boils down to:
for line in gradesfile:
s = Student(line)
students[s.id] = s
In fact you could cram it all into one line with another
list comprehension, but that seems like a step too far to me...
"Scott SA" wrote
May have been a bad assumption on my part as I envisioned pickling a
dict. and that just got too complicated.
A pickled dict?
That would be a shelve mebbe?
PS. My email is acting up, did my prev. message actually make it to
the list?
Yes, I saw it just after sending m
epetitions):
for n in range(repetitions):
# your old func code here
And call it:
func(repetitions=10) # use keyword for clarity of purpose
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor mail
"Emad Nawfal (عماد نوفل)" wrote
e...@emad-desktop:~/Desktop/py-editdist-0.3$ python setup.py build
running build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall
editdist.c:22:20: error: Python.h: No such file or directory
Looks like you need the Python source code installed,
t list archives will reveal several
discussions.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I mean you need a source installation not a binary one, it is looking for
python.h
which is one of the C header files in the Python source code.
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
From: Emad Nawfal (عماد نوفل)
To
"Matt" wrote
As an aside, why use range rather than xrange? I was under the impression
that xrange is a generator and therefore more memory efficient.
xrange was a kludge to improve on range's memory efficiency
but it is a horrible name that obscures the code.
Also it does not exist in v3 s
> this worked for me fine.
I'm glad you solved tyour problem.
But you have done so in an extremely inefficient way, both inefficient
in the way it uses computer resources - both CPU and storage, and
inefficient in the way it uses your time - way more code than you need.
If you only need an answ
very closely aligned with formal methods in
Computer Science and formal languages such as Z or VDM
For most programmers functional programming is at least
as big a conceptual leap from procedural or imperative
programming as OOP.
I'll comment on the code separately.
--
Alan Gauld
Author of
= ''
while True:#151
DisplayBoard(HANGMANPIX, MissedLetters, CorrectLetters,
First time through the program MissedLetters is empty so the for loop
never executes and Blanks is not initialised. The second for loop then
fails. You need to initialise Blanks at the head of the function.
HTH,
"spir" wrote
My app is about parsing, which input and output usually both are big
and complicated *strings*. So that I find the command line model
really unappropriate for expressing test cases and their expected
results.
Any hint/pointer/comment welcome,
What about using command line red
s in range(len(list)-1, 0, -1):
You could use list slicing here:
for passes in list[-2::-1]:
But you might find using a while loop is easier than a for loop
for bubble sort
--
Alan Gauld
Author of the Learn to Program web site
http://www.al
cking tests etc will slow
things down too. Its a good idea to have as many rows as you want to
run tests and have alternate queries hit opposite ends of the table,
or better still have several similar tables and round-robin the queries.
Just some common gotchas with database performance testing.
HTH,
dprice' / 10) + taxed price = student
you must assign a value to a variable you cannot assign
a variable to an expression.
Also, I thought the students got a discount?
This provides a surcharge!
print "your student price is 'student'
else
print "have a nice day&
ind the problem then let us know what you have discovered
when you post.
Just some thoughts for the future,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/m
launch the program in a thread. You can
then try killing the thread which may kill the program, or if not, use the
Windows API to kill the program (gets messy). This is easier on Unix
in my experience!
HTH
--
Alan Gauld
Author of the Learn to Progr
if ret==WAIT_TIMEOUT:
TerminateProcess(p._handle, 1)
return None
return p.wait()
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Offlist response...
Nice answer Denis, you neatly covered all the loose ends from
previous answers that I was just about to pick up on! :-)
"spir" wrote in message
news:20090427101523.5fc09...@o...
Le Sun, 26 Apr 2009 22:35:36 +0100,
Dayo Adewunmi s'exprima ainsi:
How can I
a) Open my she
Widgets
in most GUIs work. You call the widget with a specifically
named subset of parameters. For example:
from Tkinter import *
top = Tk()
Label(top, text="OK", foreground="Blue).pack()
Label(top, text="Cancel").pack()
top.mainloop()
The second label just adopts the default colour
"Alan Gauld" wrote
Offlist response...
Oops, not offlist! Just as well I didn't say anything offensive! :-)
Alan G
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
nd there is a Python wrapper:
http://utidylib.berlios.de/
although I've never used it.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
"Lie Ryan" wrote
documents were generated by another computer ie. they are not web page
documents.
If the source document was generated by a computer, and it produces
invalid markup, shouldn't that be considered a bug in the producing
Elementree parses xml, the source docs are html.
Va
there anything that made you think they might be?
HTH
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
= {'CBUILD':None,
'ACCEPT_KEYWORDS: None,
}
for line in fname:
for keyphrase in data:
if keyphrase in line:
output = line.split('"')[1]
data[keyphrase] = textwrap.fill(output, 80)
x27;]
Don't bother storing in variables just use the dictionary
directly in your print statements. Learn to love and use
Python's collections. They are the secret of much of Python's
power.
Just some thoughts,
--
Alan Gauld
Author of the Learn to Program web site
http://www
uspect you would be better trying on the main comp.lang.python
newsgroup.
That having been said I am constantly surprised by the breadth
of specialist knowledge on this list so you may yet get an answer
here!
--
Alan Gauld
Author of the Learn to Program web site
http://www.al
earch(r'Domains', line):
print line
But if it is a simple string you are searching for regex is overkill
and probably slower than using in.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tut
"Steve Willoughby" wrote
if re.search != (r'Domains:', line):
Because you are assigning a tuple containing a string and a line of text
to a name which is currently bound to a function object (re.search)
Actually, he's COMPARING the two, not assigning. But comparing a
function object and a
"Alan Gauld" wrote
How do I make this code print lines NOT containing the string 'Domains'?
Don't use regex, use in:
for line in log:
if "Domains" in line:
print line
Should, of course, be
if "Domains&qu
# replacement loop
for line in source:
this iterates over the characters in the string.
Remove the two source lines above and use
for line in open(source_name):
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
__
ob in the OS topic
in my tutorial. Look under the heading 'Manipulating Files'
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
null null'),
'adj' : T('adj null null'),
'adv' : T('adv null null'),}
(Yes, I know PEP8 says *not* to add spaces to line up assignments or
other
related values, but I think there are isolated cases where it does help
to
see wha
l search tools (and
what can't!) There is a very basic introduction in my tutorial which
unfortunately doesn't cover all that you need here but might be a
good starting point.
The python HOWTO is another good start and goes a bit deeper
with a different approach:
http://docs.python.o
901 - 1000 of 9948 matches
Mail list logo