[Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-30 Thread Glen
As a Python/Tkinter newbie, I thought I was getting on ok... 
then I hit this problem.

I have a canvas (c1)
A group of objects are drawn on c1 and given a tag
c1.addtag_all('group_A')

Another group of objects are drawn, I wish to tag these 'group_B'.
At the moment I 'get by' with...

a=c1.find_withtag('group_A')
b=c1.find_all()
c=b[len(a):]
for i in range(len(c)):
c1.addtag_above('group_B',len(a)+i)

I'm sure there's a "nicer" method than this, but I can't see it.
Any help would be greatly appreciated.
Thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-31 Thread Glen
On Mon, 2005-01-31 at 12:34, Kent Johnson wrote:
> Kent Johnson wrote:
> > Note that Python 2.4 has set built-in with the name 'set'. To be 
> > compatible with both you could write
> > try:
> >   set
> > except NameError:
> >   from sets import Set as set
> 
> Clarification: you don't _have_ to do this to be compatible with 2.4.
The sets module is in both 2.3 
> and 2.4. The difference in 2.4 is that set is also a built-in data
type implemented in C with the 
> same interface as sets.Set. The code above will take advantage of the
built-in set if it is 
> available, otherwise use sets.Set.
> 
In 2.4 I tried 'from sets import set'

Traceback (most recent call last):
  File "/home/glen/set4.py", line 1, in -toplevel-
from sets import set
ImportError: cannot import name set

It did allow 'from sets import *' but when using the set command
I got some odd output...

from sets import *
a=[12,54,67,47,98,76]
b=[47,54]
print set(a)-set(b)

>>> 
set(['dog','sheep,'cow'])
set([76, 98, 67, 12])
>>> 

It seems to save the output from the last use, and reproduces it later,
even after a system reboot I got the same output.
Using the inbuilt commands works fine.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-31 Thread Glen
On Mon, 2005-01-31 at 09:06, Danny Yoo wrote
> 
> Here's a small example with sets to make it more clear how this set
> manipulation stuff will work:
> 
> ###
> >>> from sets import Set
> >>> numbers = range(20)
> >>> primes = [2, 3, 5, 7, 11, 13, 17, 19]
> >>> Set(numbers) - Set(primes)
> Set([0, 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18])
> ###
Thanks Danny, sets work great (inbuilt for 2.4)
I'd never heard of them before today. I look forward
to finding other uses for them.
Now I've just got to work out how to tag a list of id's...  
There doesn't seem to be a way to tag a known id, it has to be
tagged by reference from an id above or below which seems odd!


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-31 Thread Glen
On Mon, 2005-01-31 at 18:20, Kent Johnson wrote:
> > In 2.4 I tried 'from sets import set'
> 
> should be 'from sets import Set' - the class in the sets module is called 
> Set, the builtin class is set.
> 
I tried it as 'set' and 'Set' but got the same result
> > 
> > Traceback (most recent call last):
> >   File "/home/glen/set4.py", line 1, in -toplevel-
> > from sets import set
> > ImportError: cannot import name set
> > 
> > It did allow 'from sets import *' but when using the set command
> > I got some odd output...
> > 
> > from sets import *
> > a=[12,54,67,47,98,76]
> > b=[47,54]
> > print set(a)-set(b)
> > 
> > 
> > set(['dog','sheep,'cow'])
> > set([76, 98, 67, 12])
> 
> ?? Where did the animals come from??

That's the odd output, that was from a previous set command, even after
a reboot it still came out the same.

Inbuilt set works fine.



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-31 Thread Glen
> > Have you tried the addtag_withtag() method?  It looks like it should be
> > able to do what you're thinking of.  The documentation here:
> > 
> > http://tkinter.unpythonic.net/pydoc/Tkinter.Canvas.html
> > 
> > should talk about addtag_withtag().
> 
> itemconfig() also looks promising.
> 
> http://www.pythonware.com/library/tkinter/introduction/x2017-concepts.htm
> 
Thanks Danny and Kent, I see it now.
With so many options on offer it's easy to miss the obvious.
All of this new information should keep me occupied for quite some time.
Thanks again.
Glen

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 2.4 with Mandrake 10.0 query

2005-02-02 Thread Glen
My setup is Mandrake 10.0 which came with python 2.3 and a standard
Python 2.4 build/install.
I always start Idle from an icon on my taskbar, when I click the icon,
Idle starts after a second but a small rotating timer appears over 
the taskbar for 30 seconds and then disappears.
If I close Idle immediatly, the timer still remains for the 30 seconds.
Idle/Python has always seemed to run perfectly so I have ignored 
the timer until I recently thought to run Idle from a console.
Idle/Python still works great but this output appears in the console...

[EMAIL PROTECTED] glen]$ idle
set([34, 36, 38, 39])
Failed to load extension 'CodeContext'
Traceback (most recent call last):
  File "/usr/local/lib/python2.4/idlelib/EditorWindow.py", line 737, in
load_standard_extensions
self.load_extension(name)
  File "/usr/local/lib/python2.4/idlelib/EditorWindow.py", line 747, in
load_extension
mod = __import__(name, globals(), locals(), [])
  File "/usr/local/lib/python2.4/idlelib/CodeContext.py", line 15, in ?
from sets import Set
ImportError: cannot import name Set
[EMAIL PROTECTED] glen]$

I have only just discovered the set command in python, 
and it seems a bit of a coincedence that some of the console output
lines...

set([34, 36, 38, 39])
from sets import Set
ImportError: cannot import name Set

...appear connected to code I was playing with a few days ago.
I have looked at CodeContext.py, and line 15 is 'from sets import Set'
which Python 2.4 doesn't like, as set is already built in.
I have rebuilt/installed Python 2.4, but it made no difference.

Can anyone give me a clue as to what may be going on?

Glen

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2.4 with Mandrake 10.0 query

2005-02-02 Thread Glen
On Wed, 2005-02-02 at 22:02, Danny Yoo wrote:
> On Wed, 2 Feb 2005, Glen wrote:
> 
> > [EMAIL PROTECTED] glen]$ idle
> > set([34, 36, 38, 39])
> > Failed to load extension 'CodeContext'
> > Traceback (most recent call last):
> >   File "/usr/local/lib/python2.4/idlelib/EditorWindow.py", line 737, in
> > load_standard_extensions
> > self.load_extension(name)
> >   File "/usr/local/lib/python2.4/idlelib/EditorWindow.py", line 747, in
> > load_extension
> > mod = __import__(name, globals(), locals(), [])
> >   File "/usr/local/lib/python2.4/idlelib/CodeContext.py", line 15, in ?
> > from sets import Set
> > ImportError: cannot import name Set
> 
> Hi Glen,
> 
> 
> Ah!  Check to see if there's a "sets.py" program somewhere in your current
> working directory.  It's very likely that Python is picking that up,
> instead of the 'sets' standard library module.
> 
> This is one thing that does bite people every so often, because it's all
> too easy to accidently write a program uses the same name as a standard
> library module.
> 
> I wrote a small module a while back as a proposed solution to the issue:
> 
> http://hkn.eecs.berkeley.edu/~dyoo/python/__std__/
> 
> but I don't think it's really being used.
> 
> Best of wishes to you!
> 
You're a genius! That's exactly what I'd done.
It also explains the odd results I was getting when I did import 
the sets module.
Thanks, I'll have a look at your module.
Glen

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help

2005-03-07 Thread glen
Gregory Sexton wrote:
> Thanks for the help! Sorry for the trivial questions, but I guess we all 
> have to start somewhere.  Beginning python student, OS Windows XP,using 
> Python 2.4.  Also novice to programming.  I cant get the "/a" command to 
> work.  
Shouldn't it be "\a", and it won't work from IDLE. You can save the file
with the .py extension, and double click it from the file manager and it
works fine. I booted XP JUST to test it  :)

> the way I am learning from a book entitled "Python Programming for the
> absolute beginner" by Michael Dawson. Thanks again. 

On page 25 there is a paragraph called 'trap' that warns about this.
Hope this has helped, a little.
Glen

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] XML Programs

2018-04-16 Thread Glen
Hey guys,

I'm writing a save-game editor for a game I play (just a project to learn).
But I am struggling on how to structure the code, how to store the xml data
in data structure etc,

Can anyone recommend some source I can review that reads and writes data
from an xml file.

Thanks,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML Programs

2018-04-16 Thread Glen
I understand, I'd love to use something else but the save game files are in
XML so I have no choice :'(

On 16 April 2018 at 13:54, leam hall  wrote:

> On Mon, Apr 16, 2018 at 7:10 AM, Glen  wrote:
> > Hey guys,
> >
> > I'm writing a save-game editor for a game I play (just a project to
> learn).
> > But I am struggling on how to structure the code, how to store the xml
> data
> > in data structure etc,
> >
> > Can anyone recommend some source I can review that reads and writes data
> > from an xml file.
>
> A friend's comment was "life is too short for XML". I like that. Have
> you considered JSON? Taking it a step further, MongoDB (JSON) or
> SQLite (SQL)? Both are pretty common and standard.
>
> While Python has its own stuff, like Pickle, that means you can only
> use Python. Using something like JSON or SQL means others can use the
> data and you get a chace to develop in a shared environment.  :)
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML Programs

2018-04-18 Thread Glen
Hello Stefan,

Thank you for this. That's actually quite helpful!

Regards,

On 17 April 2018 at 19:56, Stefan Behnel  wrote:

> Glen schrieb am 16.04.2018 um 13:10:
> > I'm writing a save-game editor for a game I play (just a project to
> learn).
> > But I am struggling on how to structure the code, how to store the xml
> data
> > in data structure etc,
> >
> > Can anyone recommend some source I can review that reads and writes data
> > from an xml file.
>
> Here's a tutorial for the lxml package:
>
> http://lxml.de/tutorial.html
>
> However, I'd first check if there really is no Python library yet that
> handles your "game files", whatever format they may have. One of the most
> important things to learn about software engineering is to know when *not*
> to write code to solve a problem.
>
> If you end up having (or wanting) to deal with the bare XML format
> yourself, you may consider implementing your own XML API for your format,
> so that you can nicely assign functionality to certain tags in the document
> tree. See the section on "Implementing Namespaces" here:
>
> http://lxml.de/element_classes.html
>
> Stefan
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML Programs

2018-04-19 Thread Glen
Hey guys,

I have the following code:

https://repl.it/@glendog/HurtfulPunctualInterface

Using the function I have define I can print to screen a list of books.
However, how can I search for records within the xml using an ID or the
title of the book etc? I've tried reading the tutorial but the penny is not
dropping.

On 18 April 2018 at 08:39, Glen  wrote:

> Hello Stefan,
>
> Thank you for this. That's actually quite helpful!
>
> Regards,
>
> On 17 April 2018 at 19:56, Stefan Behnel  wrote:
>
>> Glen schrieb am 16.04.2018 um 13:10:
>> > I'm writing a save-game editor for a game I play (just a project to
>> learn).
>> > But I am struggling on how to structure the code, how to store the xml
>> data
>> > in data structure etc,
>> >
>> > Can anyone recommend some source I can review that reads and writes data
>> > from an xml file.
>>
>> Here's a tutorial for the lxml package:
>>
>> http://lxml.de/tutorial.html
>>
>> However, I'd first check if there really is no Python library yet that
>> handles your "game files", whatever format they may have. One of the most
>> important things to learn about software engineering is to know when *not*
>> to write code to solve a problem.
>>
>> If you end up having (or wanting) to deal with the bare XML format
>> yourself, you may consider implementing your own XML API for your format,
>> so that you can nicely assign functionality to certain tags in the
>> document
>> tree. See the section on "Implementing Namespaces" here:
>>
>> http://lxml.de/element_classes.html
>>
>> Stefan
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Return keys with unique values from a dict

2018-05-08 Thread Glen
Hello,

I had a task to define a function that would take a dict input and return
only the keys with unique values into a list.

Here is my code, which was awarded full marks, but I am pretty unhappy with
it. I feel like I did a band-aid job after my first submission did pass
mall the unit tests. I'd appreciate any advice on a better way to do this
if anyone has some extra time.

Thanks,

def uniqueValues(theDict):
'''
theDict: a dictionary
'''
ans = []
rev = {}
toDel = []
for key, value in aDict.items():
if value not in rev:
rev[value] = key
elif value in rev:
toDel.append(value)

for item in toDel:
try:
del rev[item]
except:
pass

for item in rev:
ans.append(rev[item])

return sorted(ans)



Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] RAD GUI Development (like Visual Studio/VBA)

2018-06-29 Thread Glen
Hey guys,

Can someone advise on a RAD, drag and drop style graphical form/dialog
creator? Akin to VBA or Visual Studio that will work with Python?

I currently use the PyCharm IDE, which is fantastic. But I don't have the
time or the skill to craft it all by hand.

Thanks,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] apache2.2 - django deployment

2010-02-09 Thread Glen Zangirolami
Joson,

Everything looks good but I think the *module name is incorrect.*

Change: LoadModule *python_module *modules/mod_wsgi.so
To: LoadModule *wsgi_module *modules/mod_wsgi.so

Glen


On Tue, Feb 9, 2010 at 2:27 PM, Joson  wrote:

> Hi all,
> I wanna deploy a django program on apache2.2. So I downloaded "
> mod_wsgi-win32-ap22py26-3.0.so" and copied it into apache2.2/modules/,
> renamed "mod_wsgi.so".
>
> in httpd.conf I appended sentence:
> LoadModule python_module modules/mod_wsgi.so
>
> Then It failed to start the server:
>
> httpd.exe: Syntax error on line 128 of C:/Program Files/Apache Software
> Foundati
> on/Apache2.2/conf/httpd.conf: Can't locate API module structure
> `python_module'
> in file C:/Program Files/Apache Software
> Foundation/Apache2.2/modules/mod_wsgi.s
> o: No error
> Note the errors or messages above, and press the  key to exit.  21...
>
> Pls help me. thanks:)
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] apache2.2 - django deployment

2010-02-09 Thread Glen Zangirolami
Joson,

Everything looks good but I think the *module name is incorrect.*

Change: LoadModule *python_module *modules/mod_wsgi.so
To: LoadModule *wsgi_module *modules/mod_wsgi.so

Glen


On Tue, Feb 9, 2010 at 2:27 PM, Joson  wrote:

> Hi all,
> I wanna deploy a django program on apache2.2. So I downloaded "
> mod_wsgi-win32-ap22py26-3.0.so" and copied it into apache2.2/modules/,
> renamed "mod_wsgi.so".
>
> in httpd.conf I appended sentence:
> LoadModule python_module modules/mod_wsgi.so
>
> Then It failed to start the server:
>
> httpd.exe: Syntax error on line 128 of C:/Program Files/Apache Software
> Foundati
> on/Apache2.2/conf/httpd.conf: Can't locate API module structure
> `python_module'
> in file C:/Program Files/Apache Software
> Foundation/Apache2.2/modules/mod_wsgi.s
> o: No error
> Note the errors or messages above, and press the  key to exit.  21...
>
> Pls help me. thanks:)
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Bowing out

2010-03-03 Thread Glen Zangirolami
Thank you for all your hard work! I learned a ton from your tutorials.
Good luck on your future endeavors.


On Wed, Mar 3, 2010 at 10:18 AM, Albert-Jan Roskam  wrote:

> Hi Kent,
>
> Thank you very much for sharing your knowledge. Much appreciated!
>
> Cheers!!
> Albert-Jan
>
> ~~
> In the face of ambiguity, refuse the temptation to guess.
> ~~
>
> --- On *Wed, 3/3/10, Kent Johnson * wrote:
>
>
> From: Kent Johnson 
> Subject: [Tutor] Bowing out
> To: Tutor@python.org
> Date: Wednesday, March 3, 2010, 2:17 PM
>
>
> Hi all,
>
> After six years of tutor posts my interest and energy have waned and
> I'm ready to move on to something new. I'm planning to stop reading
> and contributing to the list. I have handed over list moderation
> duties to Alan Gauld and Wesley Chun.
>
> Thanks to everyone who contributes questions and answers. I learned a
> lot from my participation here.
>
> So long and keep coding!
> Kent
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting diagonals from a matrix

2010-03-03 Thread Glen Zangirolami
I am not really sure of a better way but if your looking for a way to make
your code cleaner or more efficient
you can try Numpy - http://numpy.scipy.org/


On Tue, Mar 2, 2010 at 4:54 PM, David Eccles (gringer) wrote:

> I've managed to drum up some code to obtain a list containing joined
> diagonal
> elements of a matrix (I'm making a word finder generator), but am wondering
> if
> there's any better way to do this:
>
> # setup so code snippet works properly
> sizeW = 4
> sizeH = 3
> puzzleLayout = ['spam'] * (sizeW * sizeH)
>
> # Starting with, say, an array with these indices:
> # 0 1 2 3
> # 4 5 6 7
> # 8 9 A B
>
> # I want the following items for a back diagonal (not in square brackets):
> # [-2],[3],8 (+5) | div 4 = -1, 1, 2
> # [-1],4,9 (+5)   | div 4 = -1, 1, 2
> # 0,5,A (+5)  | div 4 =  0, 1, 2
> # 1,6,B (+5)  | div 4 =  0, 1, 2
> # 2,7,[C] (+5)| div 4 =  0, 1, 3
> # 3,[8],[D] (+5)  | div 4 =  0, 2, 3
>
> # in other words, increase sequence by sizeW + 1 each time (sizeW - 1
> # for forward diagonals), only selecting if the line you're on matches
> # the line you want to be on
>
> # back as in backslash-like diagonal
> puzzleDiagBack = [(''.join([puzzleLayout[pos*(sizeW+1) + i] \
> for pos in range(sizeH) if (pos*(sizeW+1) + i) / sizeW == pos])) \
> for i in range(-sizeH+1,sizeW)]
> puzzleDiagBackRev = [(''.join(reversed([puzzleLayout[pos*(sizeW+1) + i] \
> for pos in range(sizeH) if (pos*(sizeW+1) + i) / sizeW == pos]))) \
> for i in range(-sizeH+1,sizeW)]
> # fwd as in forwardslash-like diagonal
> puzzleDiagFwdRev = [(''.join([puzzleLayout[pos*(sizeW-1) + i] \
> for pos in range(sizeH) if (pos*(sizeW-1) + i) / sizeW == pos])) \
> for i in range(sizeW+sizeH-1)]
> puzzleDiagFwd = [(''.join(reversed([puzzleLayout[pos*(sizeW-1) + i] \
> for pos in range(sizeH) if (pos*(sizeW-1) + i) / sizeW == pos]))) \
> for i in range(sizeW+sizeH-1)]
>
> Cheers,
> David Eccles (gringer)
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sorting algorithm

2010-03-03 Thread Glen Zangirolami
http://www.sorting-algorithms.com/

It is a fantastic website that explains each kind of sort and how it works.
They also show you visuals how the sorts work and how fast they go based on
the amount of data.

Depending on the amount/kind of data I would choose a sorting algorithm that
fits your needs.

Bubble sorts tends to get worse the larger the data set but can be very
useful to sort small lists.

On Wed, Mar 3, 2010 at 3:56 AM, C.T. Matsumoto  wrote:

> Hello,
>
> This is follow up on a question I had about algorithms. In the thread it
> was suggested I make my own sorting algorithm.
>
> Here are my results.
>
> #!/usr/bin/python
>
> def sort_(list_):
>   for item1 in list_:
>   pos1 = list_.index(item1)
>   pos2 = pos1 + 1
>   try:
>   item2 = list_[pos2]
>   except IndexError:
>   pass
>
>   if item1 >= item2:
>   try:
>   list_.pop(pos2)
>   list_.insert(pos1, item2)
>   return True
>   except IndexError:
>   pass
>
> def mysorter(list_):
>   while sort_(list_) is True:
>   sort_(list_)
>
> I found this to be a great exercise. In doing the exercise, I got pretty
> stuck. I consulted another programmer (my dad) who described how to go about
> sorting. As it turned out the description he described was the Bubble sort
> algorithm. Since coding the solution I know the Bubble sort is inefficient
> because of repeated iterations over the entire list. This shed light on the
> quick sort algorithm which I'd like to have a go at.
>
> Something I haven't tried is sticking in really large lists. I was told
> that with really large list you break down the input list into smaller
> lists. Sort each list, then go back and use the same swapping procedure for
> each of the different lists. My question is, at what point to you start
> breaking things up? Is that based on list elements or is it based on
> memory(?) resources python is using?
>
> One thing I'm not pleased about is the while loop and I'd like to replace
> it with a for loop.
>
> Thanks,
>
> T
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read XML records one by one

2010-03-08 Thread Glen Zangirolami
Another alternative to parsing XML is beautiful soup.

Website:
http://www.crummy.com/software/BeautifulSoup/

Documentation for parsing xml:
http://www.crummy.com/software/BeautifulSoup/documentation.html#Parsing%20XML

sample code:
from BeautifulSoup import BeautifulStoneSoup
xml = "Contents 1Contents 2Contents 3"
soup = BeautifulStoneSoup(xml)
print soup.prettify()
# 
#  
#   Contents 1
#   
#Contents 2
#   
#  
#  
#   Contents 3
#  
# 



On Mon, Mar 8, 2010 at 3:48 AM, Hichiro  wrote:

>
> Hi all!
> I'm trying to read one by one record in XML file to find out its tag and
> attribute for schema matching. But I haven't done yet. So, could you help
> me?!
> Thanks so much! :)
>
>
>
>
> --
> Best regards,
> Vinh NV
> CNPM K50 DHBKHN
> Y!: Vinh.dhbk
> Sky : Vinh.dhbk
> 84 976 314 988
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Communicate between a thread and the main program

2010-03-08 Thread Glen Zangirolami
I think you can use Queue to communicate between threads.

"The Queue module implements multi-producer, multi-consumer queues. It is
especially useful in threaded programming when information must be exchanged
safely between multiple threads"

http://docs.python.org/library/queue.html


On Mon, Mar 8, 2010 at 4:43 AM, Plato P.B.  wrote:

>
> Hi all,
> I have created a script in which i need to implement the communication
> between the main program and a thread.
> The thread looks for any newly created files in a particular directory. It
> will be stored in a variable in the thread function. I want to get that name
> from the main program.
> How can i do it?
>
> Thanks in Advance. :D
> --
>
>
>
>
>
>
> Rgds..
> Plato P.B.
> obscurant1st.biz/blog
>
> B'Lore  ( +919844882641)
> TsR I.( +919995317984)
> TsR II.   ( +919037036661)
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] if statement

2010-11-02 Thread Glen Clark
 File "/home/glen/workspace/test.py", line 19
if confirmed == "y":
   ^
SyntaxError: invalid syntax

Why does this not work??? PyDev says "Expected:else"

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
sorry:

NumItems = int(input("How many Items: "))


Entries = []
for In in range(0,NumItems):
   Entries.append("")



for In in range(0,NumItems):
   Entries[In]=str(input("Enter name " + str(In+1) + ": "))
   

for In in range(0,NumItems):
   print(Entries[In])

confirmed = int(input("Are you happy with this? (y/n): ")

if confirmed == "y":
   for In in range(0,NumItems):
  print(Entries[In] + ": " + str(In))
   change = int(input("Which item would you like to change: ")   
   Entries[change]=str(input("Please enter a nem name: ")
else:
#do nothing
    
print(Entries)

On Tue, 2010-11-02 at 15:05 -0400, Alex Hall wrote:
> On 11/2/10, Glen Clark  wrote:
> >  File "/home/glen/workspace/test.py", line 19
> > if confirmed == "y":
> >^
> > SyntaxError: invalid syntax
> >
> > Why does this not work??? PyDev says "Expected:else"
> It may help to see the rest of the file, or at least more of the code
> surrounding this statement.
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 
> 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
I tried that and it still does not work. 

On Tue, 2010-11-02 at 15:13 -0400, James Reynolds wrote:
> the syntax is:
> 
> 
> if True:
>  do something that you want to do if the condition you are testing
> is True, in your case when confirmed is "y"
> elif True:
>  optional: do something else when the above condition is false and
> this condition is True.
> else:
>  do something else when the above conditions are false.
> 
> 
> You can try this,
> 
> 
> if confirmed == "y":
>     stuff
> else:
> pass
> 
> 
> 
> 
> On Tue, Nov 2, 2010 at 3:02 PM, Glen Clark  wrote:
>  File "/home/glen/workspace/test.py", line 19
>if confirmed == "y":
>   ^
> SyntaxError: invalid syntax
> 
> Why does this not work??? PyDev says "Expected:else"
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
Okay, 

Thank you very much for the help guys :)

On a side note.. I didn't know you could do something like this:

x = z if 

(thus why I needed the closing parenthesis)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Looking for a tutor to review my code and provide constructive feedback.

2010-11-04 Thread Glen Clark
Hello,

I have completed my first python script. This is after watching a video
guide on python and is my first attempt at writing code in python. While the
code is not very useful I got the idea for it when googling "python projects
for beginners".

The idea was to create a script that asked the user to input a list of names
and allow the user to change a name if he wanted before confirming the
entries.

I tried to incorporate what I had learnt from the videos, such as
conditionals, error handling, functions etc... and write it how I would
write code in future.

Please if you are kind enougth to take the time to provide feedback I would
appreciate that it is constructive :)

The script is here: http://bpaste.net/show/10658/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for a tutor to review my code and provideconstructive feedback.

2010-11-05 Thread Glen Clark
*#Your code is very readable...more so than some experienced people ;^)*

Thank you, that is very motivating that I am at least on the right track!

#A few suggestions (and assuming Python 3.X, since that's what it looks
like):

Yeah it is 3.1, forgot to mention that.

# * "list" shadows a built-in type, and should not be used for variable
names.  "names" would be more appropriate.

I used list as it was a list and therefore new what argument to pass. I did
not even consider that this would be confusing! Thank you for pointing it
out.

# * input() return a string, so no need for str(input(...)).
# * range(x) is equivalent to range(0,x).

Thank you, I will note these for future code :)

#* The two loops in InitiateEntries can be consolidated:

Thank you, Seems a much better way or doing it.

#* Prefer "for name in names:" instead of using indexing, or "for idx,name
in enumerate(names):" if indexes are needed.  Example:
# * Since 1-based indexing was used elsewhere to present names to the user,
the PrintEntries display code should also use idx+1

I thought that by using an index would be an easy way for the user to select
which element of the list to edit. Not seem the enumerate keyword before so
I will look up what that does :)

 .
#  * When returning a boolean value, you can simpify:

Ah, thank you!

Really useful feedback, I will note the points highlighted for my next
mini-project. I feel it is important that I am writing proper code before
moving onto learning modules and such.



On 5 November 2010 08:32, Mark Tolonen

> wrote:

>
> "Glen Clark"  wrote in message
> news:aanlktimabbj8ae35q3ao9+xzbvtnyzbz3wrudahmn...@mail.gmail.com...
>
>  Hello,
>>
>> I have completed my first python script. This is after watching a video
>> guide on python and is my first attempt at writing code in python. While
>> the
>> code is not very useful I got the idea for it when googling "python
>> projects
>> for beginners".
>>
>> The idea was to create a script that asked the user to input a list of
>> names
>> and allow the user to change a name if he wanted before confirming the
>> entries.
>>
>> I tried to incorporate what I had learnt from the videos, such as
>> conditionals, error handling, functions etc... and write it how I would
>> write code in future.
>>
>> Please if you are kind enougth to take the time to provide feedback I
>> would
>> appreciate that it is constructive :)
>>
>> The script is here: http://bpaste.net/show/10658/
>>
>
> Your code is very readable...more so than some experienced people ;^)
>
> A few suggestions (and assuming Python 3.X, since that's what it looks
> like):
>
>  * "list" shadows a built-in type, and should not be used for variable
> names.  "names" would be more appropriate.
>  * input() return a string, so no need for str(input(...)).
>  * range(x) is equivalent to range(0,x).
>  * The two loops in InitiateEntries can be consolidated:
>
>   for In in range(NumItems):
>   names.append(input("Enter name {}: ".format(In+1)))
>
>   Or using a list comprehension:
>
>   names = [input("Enter name {}: ".format(In+1) for In in
> range(NumItems)]
>
>   * Prefer "for name in names:" instead of using indexing, or "for idx,name
> in enumerate(names):" if indexes are needed.  Example:
>
>   for idx,name in enumerate(names):
>   print("{}: {}".format(idx,name)
>
>   * Since 1-based indexing was used elsewhere to present names to the user,
> the PrintEntries display code should also use idx+1.
>   * When returning a boolean value, you can simpify:
>
>   if confirmed == 'n':
>   return True
>   else:
>   return False
>
>   To:
>
>   return confirmed == 'n'
>
> Also see PEP8 (http://www.python.org/dev/peps/pep-0008/) for Python's
> suggested coding standard.
>
> -Mark
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for a tutor to review my code and provide constructive feedback.

2010-11-05 Thread Glen Clark
Thank you very much for the feedback Luke. I have taken it onboard. I
especially like the .lower().strip()[0] method ^^

Regards,
G

On 4 November 2010 22:38, Luke Paireepinart  wrote:

> Also for your confirm entries read about sentinel values for while loops.
> It saves you repeating the conditional in the loop body. And you might want
> to .lower().strip()[0] the input choice so that they can use y, Y, yes, or
> whatever. Remember, users suck at generating accurate and correct input so
> don't give them any credit you can avoid.
>
>
> -
> Sent from a mobile device with a bad e-mail client.
> -----
>
> On Nov 4, 2010, at 3:10 PM, Glen Clark  wrote:
>
> Hello,
>
> I have completed my first python script. This is after watching a video
> guide on python and is my first attempt at writing code in python. While the
> code is not very useful I got the idea for it when googling "python projects
> for beginners".
>
> The idea was to create a script that asked the user to input a list of
> names and allow the user to change a name if he wanted before confirming the
> entries.
>
> I tried to incorporate what I had learnt from the videos, such as
> conditionals, error handling, functions etc... and write it how I would
> write code in future.
>
> Please if you are kind enougth to take the time to provide feedback I would
> appreciate that it is constructive :)
>
> The script is here: <http://bpaste.net/show/10658/>
> http://bpaste.net/show/10658/
>
> ___
>
> Tutor maillist  -   Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hi

2010-11-06 Thread Glen Clark
Luke,

I used a video from Lynda.com, simply because I already had a
subscription. The price was about $25 per month which I think is more
expensive that showmedo. Or you could buy it for $99 (Python 3 Essential
Training (DVD-ROM)). 

The video's were very good for me personally because he was straight to
the point which kept me from getting bored. 

I have recently found showmedo though and they does loog very good also.
It seems to have a lot of content on there.

Regards, 
Glen

On Sat, 2010-11-06 at 21:29 +1100, Luke Pettit wrote:
> Thanks Alan I found those about an hour ago :)
> 
> On 6 November 2010 20:11, Alan Gauld 
> wrote:
> 
> "Luke Pettit"  wrote
> 
> 
> I was interested in which video tutorials Glen was
> watching, and if anyone
> else could recommend some video tutorials to watch,
>     
> 
> I don;t know what Glen was watching but thhere are a whole
> bunch of
> videos at showmedo.com
> 
> Alan G.
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> -- 
> Luke Pettit
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hi

2010-11-06 Thread Glen Clark
Also, if you have not yet chosen an IDE I recommend eclipse with the
pydev extension. Google them or if you use gnu/linux (like ubuntu) you
can get it from the package manager. It is a very simple interface, with
syntax highlighting, debug mode and console. 

On Sat, 2010-11-06 at 14:45 +, Glen Clark wrote:
> Luke,
> 
> I used a video from Lynda.com, simply because I already had a
> subscription. The price was about $25 per month which I think is more
> expensive that showmedo. Or you could buy it for $99 (Python 3 Essential
> Training (DVD-ROM)). 
> 
> The video's were very good for me personally because he was straight to
> the point which kept me from getting bored. 
> 
> I have recently found showmedo though and they does loog very good also.
> It seems to have a lot of content on there.
> 
> Regards, 
> Glen
> 
> On Sat, 2010-11-06 at 21:29 +1100, Luke Pettit wrote:
> > Thanks Alan I found those about an hour ago :)
> > 
> > On 6 November 2010 20:11, Alan Gauld 
> > wrote:
> > 
> > "Luke Pettit"  wrote
> > 
> > 
> > I was interested in which video tutorials Glen was
> > watching, and if anyone
> > else could recommend some video tutorials to watch,
> > 
> > 
> > I don;t know what Glen was watching but thhere are a whole
> > bunch of
> > videos at showmedo.com
> > 
> > Alan G.
> > 
> > 
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> > 
> > 
> > -- 
> > Luke Pettit
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading complex data types from text file

2009-07-16 Thread Glen Zangirolami
All lines that come back from a text file come back as strings. You can use
string methods to detect the data like so:
f = open('test.txt')
lines = f.readlines()
numbers = []
strings = []

for line in lines:
if line.strip().isdigit():
numbers.append(int(line))
else:
strings.append(line.strip())

print numbers
print strings



On Wed, Jul 15, 2009 at 1:55 PM, Chris Castillo  wrote:

> I'm having some trouble reading multiple data types from a single text
> file.
>
> say I had a file with names and numbers:
>
> bob
> 100
> sue
> 250
> jim
> 300
>
> I have a few problems. I know how to convert the lines into an integer but
> I don't know how to iterate through all the lines and just get the integers
> and store them or iterate through the lines and just get the names and store
> them.
>
> please help.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question from a newbie

2009-07-22 Thread Glen Zangirolami
Deb,
For starters most of the Google enterprise runs on python.
Google App Engin e is for developers to
develop web applications on Google

There are many applications ranging from web frameworks to math modules.
Web frameworks: Django , Repoze
BFG,
Pylons , Turbo Gears ,
CherryPy 
NumPy  for math/physics.
Plone  is a content management system used by many
schools and governments.

Python website has lots of information to learn python.
Documents,
Python Enhancement Proposals ,
Communityand the Python
Package Index .

It is a beautiful language! Good Luck :)


On Tue, Jul 21, 2009 at 1:12 PM, Deb  wrote:

> My son suggested I play around with Python.  I was wondering if
> anybody has any real life applications?  It appears to be able to do quite a
> lot, but is anybody really doing it with Python?  I am very curious about
> this language.  I used to be a Clipper programmer in another life (dBASE
> compiler), and got sick when I was just entering the OOP world via Visual
> Basic and had to quit.  I just recently got my brain back, thanks to medical
> science, and would like to learn all I can about what it out there these
> days.
>
>  Thanks,
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
<><>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] code structure terminology and advice

2009-07-22 Thread Glen Zangirolami
Che,

You should check out the python styling guide here.
It give examples about how to write python code.

PEP 8 -- Style Guide for Python Code

Hope this helps!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Possible bug in django models when assigning model attribute

2009-08-19 Thread Glen Zangirolami
I ran into something weird in Django and i'm completely stumped. I got it to
work but i'm trying to understand the logic behind it.
*I have the following data model:*

from django.db import models

class Setting(models.Model):
name  = models.CharField(max_length=200)
value = models.TextField()

class Meta:
db_table = "t_settings"

def __unicode__(self):
return self.name

*I have the following form model:*

from django import forms

class GlobalSettingsForm(forms.Form):
# specify all the variables here
site_name = forms.CharField(required=True,
max_length=200,
label="Site Name",
help_text="What you want your site to be
called company name, personal name, etc."
)

site_tagline = forms.CharField(required=False,
   max_length=200,
   label="Site Tagline",
   help_text="A quick tag line on what your
site is about")

site_url = forms.URLField(required=True,
  label="Site URL",
  max_length=200,
  help_text="All links that reference your site
will use this url. I would not change this unless you are super sure." )



>From the shell I have the following code to create the form:

form = GlobalSettingsForm(data={'site_name':'test','site_url':'
http://localhost/','site_tagline':'test'})

Running a type on form i get: 
, perfect so far...

next I call form.is_valid() to get the cleaned_data attribute and all is
good.

form.cleaned_data returns {'site_name': u'test', 'site_tagline': u'test',
'site_url': u'http://localhost/'} as expected

now i want to change the information in the database so I loop through
cleaned_data, grab the object, and save:

for item in form.cleaned_data:
*setting = Setting.objects.filter(name=item)*
setting[0].value = form.cleaned_data[item]
setting[0].save()

but it *does not work*. setting[0].value = form.cleaned_data[item] fails to
assign the data

if i run it like this it works:

for item in form.cleaned_data:
*setting = Setting.objects.get(name__exact=item)*
setting.value = form.cleaned_data[item]
setting.save()

all i did was change the method used from filter to get, why does one work
and not the other??

if i create the objects individually and equate them they are the same:
setting = Setting.objects.get(name__exact=item)
setting2 = Setting.objects.filter(name=item)

setting2[0] == setting it equals True
type(setting2[0]) == setting it equals True

Also I am using, Django 1.1 with MySql Python...

Stumped.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Glen Zangirolami
If i have a list of dates:date_list =
['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']

How do I find the missing dates in the range of dates and insert them into
the list so I get?
date_list =
['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']

Hopefully the case is that I haven't found the correct python module that
does it ;)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Glen Zangirolami
Thats for all the responses. I'm going to use Kents method. I'll let you
know what I work out.
Rudiger - I did think about that. Luckily I am generating the list with a
start datetime and end datetime so if those don't exist
in either end if the list I can insert them after I check the dates between.


On Fri, Oct 9, 2009 at 5:11 PM, Rüdiger Wolf <
rudiger.w...@throughputfocus.com> wrote:

> Ah! but are we sure that the max and min dates are actually in the list?
> If there are 'missing dates' it might just be possible that it is the
> max or min date that is missing.
>
> On Fri, 09 Oct 2009 16:43 -0400, "Kent Johnson"  wrote:
> > On Fri, Oct 9, 2009 at 3:16 PM, Glen Zangirolami  >
> > wrote:
> > > If i have a list of dates:
> > > date_list =
> > >
> ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']
> > > How do I find the missing dates in the range of dates and insert them
> into
> > > the list so I get?
> > > date_list =
> > >
> ['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']
> >
> > I would do something like the following using datetime.datetime and
> > datetime.timedelta:
> > - convert each list item to a datetime object using datetime.strptime()
> > - find the min and max datetimes in the list (use min() and max()
> > - create a new list by incrementing the min date by timedelta(days=1)
> > until it hits the max date
> > - convert the new list to strings using datetime.strftime()
> >
> > Kent
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-14 Thread Glen Zangirolami
I went ahead and used a date range generator: http://dpaste.com/107140/ to
iterate over the range.I then compared the original list with the generated
one and inserted the missing dates.

I was comparing the generated dates to dates in a list list of tuples:
[(date, count), (date, count) . (date, count)]

Here is the code: http://dpaste.com/107148/

Worked perfectly. Thanks for pointing me in the correct direction.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Glen Wheeler
From: "Norman Silverstone" <[EMAIL PROTECTED]>
> On Mon, 2005-10-31 at 06:12 -0500, Kent Johnson wrote:
>> Norman Silverstone wrote:
>> > I am a beginner so, I hope what I give, makes sense. In it's simplest
>> > form what is wrong with :-
>> >
>> > n = input("Enter a number")
>> > if n % 2 != 0 and n % 3 != 0:
>> >print n, " Is a prime number"
>> >
>> This only gives the correct answer if n < 25. You can't test against a 
>> fixed list of divisors, there will always be a non-prime whose divisors 
>> are not in your list.
>
> Thank you for your comment which, if I understand you correctly, implies
> that prime numbers greater than 25 will not be recognised. Surely, that
> cannot be correct. However, if it is correct, could you please
> demonstrate what you mean for my education.
>

  The problem is that composite numbers over 25 will be recognised.
  11 is prime, but 55 is not.  Your program will tell me that 55 is prime. 
Similarly with 34, etc.
  A reasonably easy to understand prime number generator, that also operates 
quickly, is the classic sieve of Eratosthenes (sp).
  Google is your friend :).

  HTH,
  Glen 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] inside

2005-11-06 Thread Glen Wheeler
> why the following code does not work?
> [snip script]

  Give us an error message, please.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fw: point and polygon

2005-11-06 Thread Glen Wheeler

  Missed the rest of the list with this.
  Still sent to Shi however.

From: "Shi Mu" <[EMAIL PROTECTED]>
> why the following code report error?
>
> [..]
>assert pointInPoly(pointA, poly)
>assert not pointInPoly(pointB, poly)

  Assuming your function is correct, the asserts are failing, and python is
 telling you about it.  Asserts exist for many reasons but not for output.
 What you most likely want is:

 if pointInPoly(pointA, poly):
print "pointA in poly"
 else:
print "pointA not in poly"

  With a similar conditional for pointB.

  HTH,
  Glen

 L:Pyt E+++ T-- R+ P+++ D+ G+ F:*band !RL RLA-
W:AF Q+++ AI++ GFX++ SFX-- RN PO--- !Hp Re-- S+ 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] overlay

2005-11-06 Thread Glen Wheeler

  I would do this by clipping the two polygons together, and then 
calculating the area of the resultant polygon.

  You can do that using the Weiler-Atherton polygon clipping algorithm, 
which is rather common.

  Glen

From: "Shi Mu" <[EMAIL PROTECTED]>
> Is there any sample code to calculate the overlaid area between two 
> polygons?
> Thanks!
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sending email as html

2008-09-06 Thread Glen Wheeler

From: "Alan Gauld" <[EMAIL PROTECTED]>


"Lie Ryan" <[EMAIL PROTECTED]> wrote


programs which can edit PDFs which has somewhat destroyed
their value as a read-only document format for contracts, invoices
etc...


If you have used tried using any PDF editor for more than correcting
typos, you'd still consider it as a read-only document.


True. but for contracts or invoices just changing a 1 to a  7 or vice
versa can make a big difference to the money owed! And very
little difference to the layout.



 Well if it's just a matter of changing one digit this isn't so hard, since 
PDF files are not very hard to edit with a simple text editor.  (Never have 
really.) 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Multiple windows in Tkinter

2008-10-02 Thread Glen Clark
Hello,

I am a little confused how multi-windows work in Tkinter. I am currently
using it while learning to program. Using it for single window apps/scripts
is fine. However what I dont understand is:

What is toplevel? Is it the same as Tk()? Do I initialise a root using Tk()
and then use toplevel for any other windows? How do I switch between the
Windows? And while I am on the subject what is a frame and why should I use
it? atm the moment it just seems to be the same as Tk()?

Many thanks for any advice.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Looking for feedback on improving my code.

2011-05-17 Thread Glen Clark
Hello tutors,

Have not posted in a while. Started learning python a while back but had to
stop after a couple of weeks due to lack of time. Anyway pretty much
forgotten most things but if anyone has time I would love some feedback on
my application.

My main aim to to learn python, as a hobby, and participate in some open
source projects for fun.

The code is in two files, one for functions and the main file:

http://paste.pound-python.org/show/6770/ (pyDSFunctions.py)

http://paste.pound-python.org/show/6773/ (main file)

So yeah, I doubt I can write code like this with others so I would like to
get feedback on how to make this team friendly I guess. Any newbie stuff I
am doing that other coders might laugh at :P

I like this program though, so I plan to work on it for a while.

Stuff I will add later is, being able to store data collected so a user can
dive into a sub-directory with out refreshing each time (takes a while) and
also build a GUI (shouldnt be too hard as I am trying to make functions to
make the transition easier.)

Well thank you very much for readying my post!

Core
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread Glen Zangirolami
Xan, it's "not defined" because you haven't defined a function called
"function" or any variable called "function".

Nom: descripci, Tipus: , Valor: primera tasca
Nom: unmes, Tipus: , Valor:  at 0x10df736e0>

str comes back as  because str is a built-in method and python
and will always be in the namespace.

See http://docs.python.org/library/functions.html#str

On Mon, May 7, 2012 at 1:24 PM, xancorreu  wrote:

> Hi,
>
> I have this script:
>
> from types import *
>
> class Tag:
>
>def __init__(self, nom, tipus, valor):
>self.nom = nom
>self.tipus = tipus
>self.valor = valor
>
>def __str__(self):
>return "Nom: " + str(self.nom) + ", Tipus: " + str(self.tipus)  +
> ", Valor: " + str(self.valor)
>
>
> def main():
>a = Tag("descripció", str, "primera tasca")
>b = Tag("unmes", str, lambda x: x+1)
>print(a)
>print(b)
>
> if __name__ == '__main__':
>main()
>
>
> All is ok, but when I substitute b = Tag("unmes", str, lambda x: x+1) for
> b = Tag("unmes", function, lambda x: x+1) I receive an error that function
> is not globally defined variable. How can I say that function is the
> types.function? (the type of lambda x: x+1)
>
> I use python3
>
>
> Thanks in advance,
> Xan.
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Curious dictionary printing

2012-05-08 Thread Glen Zangirolami
Frankie,

Dictionaries do not sort in python because it's much faster to leave it
unordered and most of the time it isn't necessary.
If you really need ordered dictionaries you can use
http://pypi.python.org/pypi/ordereddict for Python <2.7. If you are using
python 2.7+ then you can import it from collections. See
http://docs.python.org/library/collections.html#collections.OrderedDict

Hope this helps.

Glen

On Tue, May 8, 2012 at 6:27 AM, Cranky Frankie wrote:

> On Mon, May 7, 2012 at 10:31 PM, bob gailer  wrote:
>
> > Asking why does it not do what I want is not IMHO the best way to win
> > friends here.
>
> Good morning to you to, Bob.
>
> I see now that dictionaries in Python act like relational databases in
> that there is no inherent ordering. At first, when I simply wanted to
> print one entry and it came out in what looked like a random order,
> this didn't occur to me. A normal "dictionary" is in fact ordered.
>
> Sorry for the disturbance.
>
> --
> Frank L. "Cranky Frankie" Palmeri
> Risible Riding Raconteur & Writer
> “The problem with quotes on the Internet is that
> it is often difficult to verify their authenticity.”
> - Abraham Lincoln
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shutil.rmtree clarification

2012-05-17 Thread Glen Zangirolami
Garry,

It should be able to remove the tree. I am not able to replicate this on
OSX .. yet. What are the contents of the directory and the permissions of
the directories/files? Although it should throw an exception if it is
a symbolic link or a file it can't remove.


On Thu, May 17, 2012 at 8:32 AM, Garry Willgoose <
garry.willgo...@newcastle.edu.au> wrote:

> /Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/shutil.py
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Joining all strings in stringList into one string

2012-05-30 Thread Glen Zangirolami
Seems like a lot of extra work for joining the strings. You should only
need:

''.join(['very', 'hot', 'day']) (no spaces)
' '.join(['very', 'hot', 'day']) (if you want spaces)

glen


On Wed, May 30, 2012 at 11:21 AM, Akeria Timothy wrote:

> Hello all,
>
> I am working on learning Python(on my own) and ran into an exercise that I
> figured out but I wanted to know if there was a different way to write the
> code? I know he wanted a different answer for the body because we haven't
> gotten to the ' '.join() command yet.
>
> This is what I have:
>
> def joinStrings(stringList):
>  string = []
> for string in stringList:
> print ''.join(stringList)
>
>
> def main():
> print joinStrings(['very', 'hot', 'day'])
> print joinStrings(['this', 'is', 'it'])
> print joinStrings(['1', '2', '3', '4', '5'])
>
> main()
>
>
> thanks all
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need reference materials to learn flask + python for payroll project that would run both in windows (PC) and android/iOS.

2016-09-13 Thread Glen Reytas
Hi,

I have a basic knowledge in Python and I would like to enhance it by
engaging in a payroll project. For you to gauge my coding level, I finished
the Python course at codecademy.com but it was 2-3 years ago. Since then I
haven't coded aside from HTML.

So, I would appreciate if you could provide me a series of topics that
would help me code my first python project and be online at the end of it.
Accessible through PC and mobile.

Hoping,

Glen
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with Python

2014-05-11 Thread Glen Chan
Hello, I am a student trying to figure out Python. I am getting errors that I 
don't know how to fix. What do you do after you get the error message and 
something is highlighted? Does that have to be deleted? Anyway, here is what I 
mean...
 
 
#>>> The Dice Game
#add libraries needed
import random
#the main function
def main():
print
#initialize variables
playerOne = 'No Name'
playerTwo = 'No Name'

#call to inputNames
playerOne, playerTwo = inputNames(playerOne, playerTwo)
#while loop to run program again
while endProgram == 'no':
#initialize variables
 winnersName = 'NO NAME'
 p1number = 0
 p2number = 0
#call to rollDice
 winnerName = rollDice(p1number, p2number, playerOne, playerTwo, winnerName)

#call to displayInfo
 winnerName
endProgram = raw_input('Do you want to end program? (Enter yes or no): 
')



#this function gets the players names
def inputNames(playerOne, playerTwo):
playerOne = raw_input("Enter Name")
playerTwo = raw_input("Enter Name")   
 
return playerOne, playerTwo
#this function will get the random values
def rollDice(p1numer, p2numer, playerOne, playerTwo, winnerName):
 p1number = random.randint(1, 6)
 p1number = random.randint(1, 6)
 
#this function displays the winner
 
if p1number == p2number:
winnerName = "TIE"
elif p1number > p2number:
winnerName = playerOne
else:
winnerName = playerTwo
return winnerName

# calls main
main()
 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with Python

2014-05-16 Thread Glen Chan
Hello, I am student trying to fugure out why when I enter any number it says 
error. It's only suppose to do that  if it's out the 1-10 range. Please help. 
Thank you.
 
number = input('Enter a number between 1 and 10: ')
while number < 1 or number > 10:
  print 'Please enter a number between 1 and 10'
  number = input('Enter a number between 1 and 10: ')
  
number = input('Enter a number between 1 and 10: ')  
while number > 1 or number < 10:
  print 'Error'
  number = input('Enter a number between 1 and 10: ')  
endProgram = raw_input('Do you want to end program? (Enter no or yes): ')
while not (endProgram == 'yes' or endProgram == 'no'):
   print 'Please enter a yes or no'
endProgram = raw_input('Do you want to end program? (Enter no to process a new 
set of scores): ')
 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Pease help

2014-06-06 Thread Glen Chan
Hello I am a student trying to figure out this program. Here is my objective 
and program below. What am I doing wrong? I can't get this to work.
 



Calculate the average pints of
blood donated during a blood drive.  The
program should take in the number of pints donated during the drive, based on a
seven hour drive period.  The average
pints donated during that period should be calculated and written to a
file.  Write a loop around the program to
run multiple times.  The data should be
appended to the file to keep track of multiple days.  If the user wants to 
print data from the
file, read it in and then display it. 
Store the pints per hour and the average pints donated in a file called
blood.txt.  





 #the
main function

def
main():


  endProgram = 'no'


  print


  while endProgram == 'no':


option = 0


print


print 'Enter 1 to enter in new data and
store to file'


print 'Enter 2 to display data from the
file'


option = input('Enter now ->')


print


 
# declare variables

pints = [0] * 7


totalPints = 0


averagePints = 0


if option == 1:



  # function calls

  pints = getPints(pints)


  totalPints = getTotal(pints, totalPints)


  averagePints = getAverage(totalPints,
averagePints)


  
else:


endProgram = raw_input('Do you want to end
program? (Enter no or yes): ')


while not (endProgram == 'yes' or
endProgram == 'no'):

  print 'Please enter a yes or no'


  endProgram = raw_input('Do you want to
end program? (Enter no or yes): ')



 #the
getPints function

def
getPints(pints):


  counter = 0


  while counter < 7:


  pints[counter] = input('Enter pints
collected: ')


  counter = counter + 1


  return pints


 
#the
getTotal function

def
getTotal(pints, totalPints):


  counter = 0


  while counter < 7:


totalPints = totalPints + pints[counter]


counter = counter + 1


  return totalPints



 #the
getAverage function

def
getAverage(totalPints, averagePints):


  averagePints = float(totalPints) / 7


  return averagePints






#the
writeToFile function

def
writeToFile(averagePints, pints):





#the
readFromFile function


 def readFromFile(averagePints, pints):



#
calls main


main()


  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to expand "../../myfile"

2014-07-18 Thread Glen Jarvis
On Fri, Jul 18, 2014 at 6:33 PM, Alex Kleider  wrote:

> Is there a function that can return the full path name when provided with
> something along the lines of
> "../../myfile"?
>

The OS module is great at this. Here's an example:

import os

MYFILE= '../../myfile'

print "MYFILE", MYFILE

print "abspath", os.path.abspath(MYFILE)


And, here is the output:

prompt> python example01.py

MYFILE ../../myfile

abspath /Users/glenjarvis/Desktop/test/myfile


>
> Just to be able to glean the current working directory would suffice. (I
> could use a shell command if I had to but was hoping it could be done all
> within Python.
>

You can also glean just the current working directory:

import os

print "pwd", os.getcwd()


And it's output:

prompt> python example02.py

pwd /Users/glenjarvis/Desktop/test/x/y


Cheers,


Glen
-- 

"You grab mindshare by being there."

-- Alex Martelli

   Bay Area Python Interest Group Talk

   24-Oct, 2013
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor