Re: [newbie] advice and comment wanted on first tkinter program

2014-01-21 Thread Jean Dupont
Op maandag 20 januari 2014 07:24:31 UTC+1 schreef Chris Angelico:
> On Mon, Jan 20, 2014 at 3:04 PM, Jean Dupont  wrote:
> > I started a thread "[newbie] starting geany from within idle does not
> > work" both here and in the raspberry pi forum. I just wondered why I never
> > got an answer concerning that topic.
> I saw that thread. It looked like a R-Pi problem, not a Python one, so
> I didn't respond because I don't have an R-Pi. If you get no response
> on the R-Pi forum, you might want to see if you can duplicate the
> issue on a desktop computer - preferably on Win/Mac/Lin, as those are
> the platforms most people use. That, with exact steps to repro (which
> it looks like you gave for the R-Pi, though again I can't verify),
> would get some interest.
I did try to do the same on my linux desktop computer, but the problem is,
it has another desktop environment (KDE4). In the rpi-environment it is
possible
(but it doesn't work) to change the default IDLE-editor by right-clicking
the idle-icon and choosing geany in stead of leafpad, however the same
can't be done
in KDE4, I hoped to find a similar setting once running IDLE in
Options-->Configure IDLE, but nothing there neither. I also looked
unsuccessfuly in the .idlerc-directory for a config-file. Hence my initial
question.

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Diving in to Python - Best resources?

2014-01-21 Thread Ashish Panchal
The best resource I think is documentation provided by python
http://docs.python.org/
If You need to learn python from scratch http://docs.python.org/tut/tut.html
If you need a book for reference http://diveintopython3.ep.io/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-21 Thread Roy Smith
In article ,
 Rustom Mody  wrote:

> I was working in a large sw-development company some years ago.
> One day unexpectedly I found I could not download any more the FOSS sw
> I regularly use.  What happened??
> 
> Evidently a programmer had copied GPL code off the net, passed it off
> as his own, it had gone past the local company'a managers and been
> detected by the off-shore client-company.  Evidently a dose of GPLd
> code is as salutary for the health of commercial sw companies as a
> polonium capsule is for humans.

Absolutely.  Most open-source code comes with license restrictions.  
"You are free to use this, but if you do, you are obligated to do these 
things..."  Certainly, GPL comes with obligations.  If one of your 
employees grabs some GPL stuff off the net and puts it into your 
product, you are now obligated to do those things.  Those may be 
obligations you're not willing to commit to.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Self healthcheck

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 1:51 PM, Asaf Las  wrote:
> When designing long running background process
> is it feasible to monitor object/memory leakage due
> to improper programming?

I assume you're talking about pure Python code, running under CPython.
(If you're writing an extension module, say in C, there are completely
different ways to detect reference leaks; and other Pythons will
behave slightly differently.) There's no way to detect truly
unreferenced objects, because they simply won't exist - not after a
garbage collection run, and usually sooner than that. But if you want
to find objects that you're somehow not using and yet still have live
references to, you'll need to define "using" in a way that makes
sense. Generally there aren't many ways that that can happen, so those
few places are candidates for a weak reference system (maybe you map a
name to the "master object" representing that thing, and you can
recreate the master object from the disk, so when nothing else is
referring to it, you can happily flush it out - that mapping is a good
candidate for weak references).

But for most programs, don't bother. CPython is pretty good at keeping
track of its own references, so chances are you don't need to - and if
you're seeing the process's memory usage going up, it's entirely
possible you can neither detect nor correct the problem in Python code
(eg heap fragmentation).

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-21 Thread Rustom Mody
On Wednesday, January 22, 2014 6:21:37 AM UTC+5:30, Steven D'Aprano wrote:
> On Mon, 20 Jan 2014 19:17:35 +1100, Ben Finney wrote:

> > indar kumar writes:
> >> Hint would have been enough but I was strictly discouraged.
> > You asked for private help, specifically to subvert the rules against
> > plagiarism you're subject to.
> > So no, I don't believe this modification of your request to be sincere.
> > You asked for help cheating, and you were refused. Please take a hint,
> > and do your assignment under the terms your teacher has set.

> That is the harshest, least "good faith" interpretation of the OP's post 
> I have ever read. It doesn't look to me like that attitude is intended to 
> be welcoming to students who are trying to walk the narrow tightrope of 
> being part of a community of programmers who value sharing and 
> collaboration while avoiding running foul of overly strict academic rules 
> about so-called plagiarism.

I was working in a large sw-development company some years ago.
One day unexpectedly I found I could not download any more the FOSS sw
I regularly use.  What happened??

Evidently a programmer had copied GPL code off the net, passed it off
as his own, it had gone past the local company'a managers and been
detected by the off-shore client-company.  Evidently a dose of GPLd
code is as salutary for the health of commercial sw companies as a
polonium capsule is for humans.  Hence the chaos.

So treating Ben's strictures as *purely* academic is at least as harsh
as the strictures themselves

IOW plagiarism is not about some kind of morality but about following
some rules -- which are usually quite arbitrary.

Heck even different free licenses quarrel about what constitutes right
and wrong.  And as a consequence of all this, courses and entire
degrees in IP are becoming fashionable
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread Tim Chase
On 2014-01-22 02:46, John Gordon wrote:
> > FarmID  AddressNumAddressName
> > 1   1067  Niagara Stone
> > 2   4260  Mountainview
> > 3   25Hunter
> > 4   1091  Hutchinson
> 
> > I have struggled with this for a while and know there must be a
> > simple method to achieve this result.
> 
> for line in input_lines:
> fields = line.split()
> farm_id = fields[0]
> address_num = fields[1]
> address_name = ' '.join(fields[2:])

Or, you can split of just the parts you need:

  for line in input_lines:
farm_id, street_no, street_name = line.split(None, 2)

It doesn't address the issues that Ben raised about the crazy formats
you can find in addresses, but address-parsing is an twisty maze of
passages all alike.

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list


Self healthcheck

2014-01-21 Thread Asaf Las
Hi 

When designing long running background process 
is it feasible to monitor object/memory leakage due 
to improper programming?
If it could be possible to make module which monitor and 
record trends if alive objects then event can be 
generated and logged if noof "zombie" objects 
are to increase in longer run.

Would the gc.count() serve for such purpose?

Thanks

Asaf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread John Gordon
In <9fe1b47b-65ce-4063-9188-07b81cdba...@googlegroups.com> Shane Konings 
 writes:

> I have the following sample from a data set and I am looking to split the 
> address number and name into separate headings as seen below.

> FarmIDAddress
> 1 1067 Niagara Stone
> 2 4260 Mountainview
> 3 25 Hunter
> 4 1091 Hutchinson
> 5 5172 Green Lane
> 6 500 Glenridge
> 7 471 Foss
> 8 758 Niagara Stone
> 9 3836 Main
> 101025 York


> FarmIDAddressNumAddressName
> 1 1067  Niagara Stone
> 2 4260  Mountainview
> 3 25Hunter
> 4 1091  Hutchinson
> 5 5172  Green Lane
> 6 500   Glenridge
> 7 471   Foss
> 8 758   Niagara Stone
> 9 3836  Main
> 101025  York

> I have struggled with this for a while and know there must be a simple
> method to achieve this result.

for line in input_lines:
fields = line.split()
farm_id = fields[0]
address_num = fields[1]
address_name = ' '.join(fields[2:])

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Diving in to Python - Best resources?

2014-01-21 Thread notbob
On 2014-01-20, Matt Watson  wrote:

> My question to you guys is... for someone like me, what route would
> you take to learning Python? "Learn Python the Hard Way" sounds like
> a good route, but I prefer some testimony before I make a
> purchase. 

You sound a lot like myself, in that you are easily frustrated.  I
discovered long ago I'm NOT a programmer.  I've dipped a toe into
basic, html, C, bash script, lisp, etc, but have never gotten beyond
the "pissed" and/or "bored-to-tears" level.  Much of this is due to
almost every single book/tutorial/howto/etc having either mistakes in
the code or crippling omissions, requiring a 30 min search on the web,
jes like you sed.  I hate that!

So, Learning Python the Hard way.  I love it!!  No mistakes.  No
omissions.  Everthing explained.  I'm about a doz lessons in and the
author has me chuckling (he has a sense of humor) with pleased delight
after I successfully complete a lesson.  I also use the 2.7.6 Python
Standard Library as a reference in case I wanna know more.  I'm
enrolled in an online python course starting in Mar and I'm hoping
LPtHW will get me sufficiently primed.  I think it will.  I highly
recommend it.

nb




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: http://bugs.python.org/user?@template=rego_progress broken?

2014-01-21 Thread Terry Reedy

On 1/21/2014 4:00 PM, Charles Hixson wrote:

I have tried to register at http://bugs.python.org, and got as far as
this page, where I am told:
You will shortly receive an email to confirm your registration. To
complete the registration process, visit the link indicated in the email.



But it hasn't arrived after over a day.


That happens occasionally, unknown why. I believe the usual advice is 
try again.



This case isn't too important, as I was just going to request a
documentation change, but it happening may be more important than what I
would have entered.


You can post your request here for discussion.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread Anders Wegge Keller
Shane Konings  writes:

...

> The following is a sample of the data. There are hundreds of lines
> that need to have an automated process of splitting the strings into
> headings to be imported into excel with theses headings

> ID  Address  StreetNum  StreetName  SufType  Dir   City  Province  PostalCode
> 
> 
> 1 1067 Niagara Stone Rd, W, Niagara-On-The-Lake, ON L0S 1J0
> 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2
> 3 25 Hunter Rd, Grimsby, E, ON L3M 4A3
> 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0
> 5 5172 Green Lane Rd, Lincoln, ON L0R 1B3
> 6 500 Glenridge Ave, East, St. Catharines, ON L2S 3A1
> 7 471 Foss Rd, Pelham, ON L0S 1C0
> 8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0
> 9 3836 Main St, North, Lincoln, ON L0R 1S0
> 101025 York Rd, W, Niagara-On-The-Lake, ON L0S 1P0

 The input doesn't look consistent to me. Is Dir supposed to be an
optional value? If that is the only optional, it can be worked
around. But if the missing direction (I'm guessing) is due to
malformed input data, you have a hell of a job in front of you.

 What do you want to do with incomplete or malformed data? Try to
parse it as a "best effort", or simply spew out an error message for
an operator to look at?

 In the latter case, I suggest a stepwise approach:

* Split input by ',' ->res0

* Split the first result by ' ' -> res

-> Id = res[0]
-> Address = res[1:]
-> StreetNum = res[1]
-> StreetName= res [2:]
-> SufType = res[-1]

* Check if res0[1] looks like a cardinal direction
 If so Dir = res0[1]
 Otherwise, croak or use the default direction. Insert an element in
 the list, so the remainder is shifted to match the following steps.

-> City = res0[2]

* Split res0[3] by ' ' -> respp

respp[0] -> Province
respp[1:] -> Postcode


 And put in som basic sanitation of the resulting values, before
committing them as a parsed result. Provinces and post codes, should
be easy enough to validate against a fixed list. 

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-21 Thread Steven D'Aprano
On Mon, 20 Jan 2014 19:17:35 +1100, Ben Finney wrote:

> indar kumar  writes:
> 
>> Hint would have been enough but I was strictly discouraged.
> 
> You asked for private help, specifically to subvert the rules against
> plagiarism you're subject to.
> 
> So no, I don't believe this modification of your request to be sincere.
> You asked for help cheating, and you were refused. Please take a hint,
> and do your assignment under the terms your teacher has set.

That is the harshest, least "good faith" interpretation of the OP's post 
I have ever read. It doesn't look to me like that attitude is intended to 
be welcoming to students who are trying to walk the narrow tightrope of 
being part of a community of programmers who value sharing and 
collaboration while avoiding running foul of overly strict academic rules 
about so-called plagiarism.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-21 Thread Steven D'Aprano
On Mon, 20 Jan 2014 18:39:44 +1100, Ben Finney wrote:

> But sometimes different skills are being examined, and the student
> should be exercising skills on their own without basing it directly on
> the work of others. In these cases, penalties for plagiarism are
> appropriate, would you agree?

How can anyone possibly agree without knowing what those penalties are, 
what the definition of plagiarism being used is, and how guilt or 
innocence is determined?

According to some people in a much better position to judge, significant 
parts of academia has collectively gone mad over so-called plagiarism.

"I started off researching the subject of plagiarism thinking that
sensitivity on the issue was getting a little bit out of hand. What
I found when I viewed actual guidelines and articles on the subject
was just plain appalling. Academia has simply gone crazy on this
subject; not figuratively crazy, but certifiably, clinically,
sociopathically insane. I'm talking delusional, loss of contact 
with reality insanity."
-- Professor Steven Dutch, University of Wisconsin

http://www.uwgb.edu/dutchs/PSEUDOSC/PlagShame.HTM

More here:

http://www.uwgb.edu/dutchs/PSEUDOSC/PlagiarNonsense.HTM

According to Dutch, the University of Phoenix academic guidelines 
includes *failing to give a page number* of an otherwise fully cited 
source as plagiarism.

If you read nothing else, read the second link, as Dutch gives practical 
guidelines for distinguishing significant and unethical plagiarism from 
insignificant and normal borrowing and sharing.


Let's take this word of advice from "Plagiarism Today":

   [quote]
   In the end, it comes down to the same tried and true system of 
   always attributing any content that you use, no matter how small, 
   and always showing respect for the words of others, even if you 
   have permission to use them.
   [end quote]

http://www.plagiarismtoday.com/2008/02/20/the-obama-plagiarism-scandal/


Do you notice the assumption made? Let me highlight it for you:

   THE WORDS OF OTHERS


The hidden assumption here is that *words are property*, that they belong 
to whomever first publishes them. Having now written those few words, 
nobody else is permitted to use those same words in the same order 
without crediting me. Failure to credit me is a sin of the highest order, 
enough to get you kicked out of your university, your name blackened. 
Unless, of course, somebody else wrote those words before me, in which 
case *my ignorance* of that earlier usage does not diminish the magnitude 
of my sin. In that regard, plagiarism is rather like patent infringement.

This attitude is part of the compartmentalisation of culture into walled 
gardens, where nothing can be done without the permission of the 
"intellectual property owner". This is dangerous enough when it comes to 
ordinary, regular language, but it is astonishingly harmful if applied to 
code. It goes against the principles of openness and freedom which the 
FOSS movement stands for.

Code, for the most part, is extremely cliched. Very little code is 
original, and none of it is created in isolation. There are only so many 
ways to walk a list, or search a body of text for a word, or calculate 
the cosine of a float. You sometimes have the option of shuffling the 
order of operations around a bit, or changing variable names, or slight 
modifications of some algorithm. As a community, programmers may not 
always share code, but they share ideas, coding idioms and algorithms. 
The academic definition of plagiarism, if applied in its full and 
strictest form, would essentially make coding impossible.

We do not know how strict the OP's college is about so-called plagiarism, 
whether they only intend to come down on outright copying of significant 
bodies of code, or whether they have a tendency to go after trivial 
borrowing of simple idioms or minor duplication of insignificant portions 
of the program. (If I walk a linked list using mynode = mynode.next, and 
you use the same variable names, is that an indication of copying?) 
Without knowing what the OP's college considers plagiarism, how can judge 
the OP's reaction to it?



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Modifying the default argument of function

2014-01-21 Thread Asaf Las
On Tuesday, January 21, 2014 9:46:16 PM UTC+2, Chris Angelico wrote:
> On Wed, Jan 22, 2014 at 6:36 AM, Mû  wrote:
> > These were clear and quick answers to my problem. I did not think of this
> > possibility: the default argument is created once, but accessible only by
> > the function, therefore is not a global variable, whereas it looks like if
> > it were at first glance.
> You can actually poke at the function a bit and see what's happening.
> Try this in the interactive interpreter:
> >>> def f(x=[2,3]):
> x.append(1)
> return x
> >>> f()
> [2, 3, 1]
> >>> f()
> [2, 3, 1, 1]
> >>> f.__defaults__
> ([2, 3, 1, 1],)
> 
> The __defaults__ attribute of a function is a tuple of its parameter
> defaults. You can easily see there that the list has changed as you
> changed it in the function. You could check it with id() or is, too:
> >>> id(f.__defaults__[0])
> 24529576
> >>> id(f())
> 24529576
> >>> f() is f.__defaults__[0]
> True
> ChrisA

that reminds me C's static :-)

def func(y, x = [1]):
if y != 1 :
func.__defaults__[0][0] = y
print(func.__defaults__[0])

func(0)
func(2)
func(1)

[0]
[2]
[2]

p.s. Mu, thanks for question!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread Asaf Las
On Wednesday, January 22, 2014 1:49:16 AM UTC+2, Shane Konings wrote:
> I have the following sample from a data set and I am 
> looking to split the address number and name into separate headings 
>as seen below.
> I have struggled with this for a while and know there must be a simple method 
> to achieve this result.

input = '''11067 Niagara Stone
24260 Mountainview
325 Hunter
41091 Hutchinson
55172 Green Lane
6500 Glenridge
7471 Foss
8758 Niagara Stone
93836 Main
101025 York '''

tlist = input.splitlines()
for k in tlist:
print(k.split())



do with 'k' whatever you wish 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread Shane Konings
inHandler = open(inFile, 'r')
outHandler = open(outFile, 'w')
outHandler.write('ID\tAddress\tStreetNum&Name\tSufType\tDir\tCity\tProvince\tPostalCode\n')
for line in inHandler:
str = line.replace('FarmID\tAddress','')
outHandler.write(str[0:-1])
str = str.replace(', ON', '\t ON\t')
str = str.replace(' Rd,', '\t Rd\t \t')
str = str.replace(' Rd ', '\t Rd\t \t')
str = str.replace(' St,', '\t St\t \t')
str = str.replace(' St ', '\t St\t \t')
str = str.replace(' Ave', '\t Ave\t \t')
str = str.replace(' Pky', '\t Pky\t \t')
str = str.replace(' Lane, ', '\t Lane\t \t')
str = str.replace(', Lane, , Rd,', ' Lane\t Rd\t')
str = str.replace(' Dr', '\t Dr\t \t')
str = str.replace(' Sq', '\t Sq\t \t')
str = str.replace(' Pl', '\t Pl\t \t')
str = str.replace('\t \tN,', '\tN\t')
str = str.replace('\t \t N,', '\tN\t')
str = str.replace(' , North ', ' N\t')
str = str.replace(' ,S ', ' S\t')
str = str.replace(' , South ', ' S\t')
str = str.replace('\t \tE,', '\tE\t')
str = str.replace(' , East ', ' E\t')
str = str.replace('\t \tW,', '\tW\t')
str = str.replace('\t \t West', '\tW\t')
str = str.replace(',.', '.')
str = str.replace(',', '\t')
str = str.replace(',,', '\t')
str = str.replace(', Service', ' Service')
str = str.replace('\t \t\t', '\t\t')
outHandler.write(str[1:])
inHandler.close()
outHandler.close()


That is the code i currently have.

The following is a sample of the data. There are hundreds of lines that need to 
have an automated process of splitting the strings into headings to be imported 
into excel with theses headings 

ID  Address  StreetNum  StreetName  SufType  Dir   City  Province  PostalCode


1   1067 Niagara Stone Rd, W, Niagara-On-The-Lake, ON L0S 1J0
2   4260 Mountainview Rd, Lincoln, ON L0R 1B2
3   25 Hunter Rd, Grimsby, E, ON L3M 4A3
4   1091 Hutchinson Rd, Haldimand, ON N0A 1K0
5   5172 Green Lane Rd, Lincoln, ON L0R 1B3
6   500 Glenridge Ave, East, St. Catharines, ON L2S 3A1
7   471 Foss Rd, Pelham, ON L0S 1C0
8   758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0
9   3836 Main St, North, Lincoln, ON L0R 1S0
10  1025 York Rd, W, Niagara-On-The-Lake, ON L0S 1P0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread Ben Finney
Shane Konings  writes:

> I have the following sample from a data set and I am looking to split
> the address number and name into separate headings as seen below.
>
> FarmIDAddress
> 1 1067 Niagara Stone
> 2 4260 Mountainview
> 3 25 Hunter
> 4 1091 Hutchinson
> 5 5172 Green Lane
> 6 500 Glenridge
> 7 471 Foss
> 8 758 Niagara Stone
> 9 3836 Main
> 101025 York

If it is *always* the case that you just want to split the string on the
first space (' ', U+0020) character, then this will do the job:

>>> street_address = "1067 Niagara Stone"
>>> (street_number, street_name) = street_address.split(' ', 1)
>>> street_number
'1067'
>>> street_name
'Niagara Stone'

But that's a very dubious assumption. Are you sure your data contains no
examples like:

PO Box 27
Unit 6, 52 Watford Avenue
Lot D property 107 Sandusky Road

etc.? What is your policy for dealing with data which isn't structured
as you assume?

-- 
 \ “All my life I've had one dream: to achieve my many goals.” |
  `\—Homer, _The Simpsons_ |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-21 Thread Steven D'Aprano
Hi Indar,

On Sun, 19 Jan 2014 23:55:59 -0800, indar kumar wrote:

> If you allow me I can post a small part of that assignment, it just
> requires the manipulation with dictionary which I am not getting. I am
> not asking to write a code for me. But a small hint would get me out of
> trouble.


In all this discussion about plagiarism, we seem to have forgotten about 
you! Sorry about that.


Yes, feel free to ask your question about manipulating dictionaries, and 
we will try to answer. The more general your question (in the sense of 
not being specific to your project), the less you need to worry about 
plagiarism.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread Shane Konings

> I don't have any code to split that part up. There is other information 
> following the street name such as street suffix, city, province, postal code, 
> etc. I have been able to split the rest of it up based on certain criteria 
> but have had no luck with splitting up the street name from the street number.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Separate Address number and name

2014-01-21 Thread Anders Wegge Keller
Shane Konings  writes:

> I have struggled with this for a while and know there must be a
> simple method to achieve this result.

 There are several. But without seeing the code you have already
written, it's har to help you improve it.

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*
-- 
https://mail.python.org/mailman/listinfo/python-list


Separate Address number and name

2014-01-21 Thread Shane Konings
I have the following sample from a data set and I am looking to split the 
address number and name into separate headings as seen below.

FarmID  Address
1   1067 Niagara Stone
2   4260 Mountainview
3   25 Hunter
4   1091 Hutchinson
5   5172 Green Lane
6   500 Glenridge
7   471 Foss
8   758 Niagara Stone
9   3836 Main
10  1025 York


FarmID  AddressNumAddressName
1   1067  Niagara Stone
2   4260  Mountainview
3   25Hunter
4   1091  Hutchinson
5   5172  Green Lane
6   500   Glenridge
7   471   Foss
8   758   Niagara Stone
9   3836  Main
10  1025  York

I have struggled with this for a while and know there must be a simple method 
to achieve this result.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: autoconf tools and python3 3m 3dm

2014-01-21 Thread Asaf Las
On Tuesday, January 21, 2014 7:55:13 PM UTC+2, Mark Heieis wrote:
> Hi,
> would work either as one would need to know in advance specifically 
> which one to call and there'd be extra work to extract the full version 
> info, etc. ("$python3-config --includes" yields 
> -I/usr/include/python3.3m -I/usr/include/python3.3m)
> Has anyone else come up against this? If so, what was the solution?
> BTW - anyone know what the 'm' and 'dm' suffixes indicate?
> TIA.

I use recommended approach as below: 
./configure --prefix=/usr/local
make && make altinstall

and  have base 2.6 came with CENTOS, 2.7 and 3.3 installed later
and working without problem. see below

[root@localhost etc]# which python3.3
/usr/local/bin/python3.3
[root@localhost etc]# which python2.7
/usr/local/bin/python2.7
[root@localhost etc]# which python
/usr/bin/python

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Implementing append within a descriptor

2014-01-21 Thread Joseph L. Casale
> You're going to have to subclass list if you want to intercept its
> methods. As I see it, there are two ways you could do that: when it's
> set, or when it's retrieved. I'd be inclined to do it in __set__, but
> either could work. In theory, you could make it practically invisible
> - just check to see if you're trying to __set__ a list, and if you
> are, set a magical list instead.
 
Hey Chris,
That actually is sufficient, assignment can be intercepted and retyped so
an append will accomplish what I need.

Thanks!
jlc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running pywin32-218.win32-py2.7.exe (win32 package for Python) results in error “The file exists”

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 5:45 AM, Ziv Tepman  wrote:
> I am trying to install the Python module "win32" but whenever I click on the
> exe file (pywin32-218.win32-py2.7.exe) I get the message "The file exists
> Could not create temporary file", and when I click OK, I get the message,
> "Setup program invalid or damaged." I have chosen the appropriate build. How
> might I fix this error?  Thanks!

Do you have a way to check that the file was downloaded correctly?
Alternatively, just try redownloading it - maybe you got a broken file
somehow.

Since you're not talking about Python itself but about a specific
module, it would help if you provided a link to the page you got it
from, too. Thanks! :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 1.0 - release date?

2014-01-21 Thread Skip Montanaro
> I want to say August of 1993, but there are apparently those who disagree.

Misc/HISTORY says 26 January 1994:

===
==> Release 1.0.0 (26 January 1994) <==
===

Actually, Misc/HISTORY has release headings going back as far as 0.9.0
(February 1991).

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to avoid spaghetti in Python?

2014-01-21 Thread andrea crotti
2014/1/21 CM :
> I've been learning and using Python for a number of years now but never 
> really go particularly disciplined about all good coding practices.  I've 
> definitely learned *some*, but I'm hoping this year to take a good step up in 
> terms of refactoring, maintainability, and mostly just "de-spaghettizing" my 
> approach to writing Python programs.
>

It's not really a problem of Python, you just want to learn more about
OO principles and good design practices, and about that there are
hundreds of good books to read!

>
> A few specific questions in this area...
>
> 1) One of my main "spaghetti problems" is something I don't know what to ever 
> call.  Basically it is that I sometimes have a "chain" of functions or 
> objects that get called in some order and these functions may live in 
> different modules and the flow of information may jump around quite a bit, 
> sometimes through 4-5 different parts of the code, and along the way 
> variables get modified (and those variables might be child objects of the 
> whole class, or they may just be objects that exist only within functions' 
> namespaces, or both).  This is hard to debug and maintain.  What would people 
> recommend to manage this?  A system of notes?  A way to simplify the flow?  
> And what is this problem called (if something other than just spaghetti code) 
> so I can Google more about it?
>

Just define clearly objects and methods and how they interact with
each other in a logic way, and you won't have this problem anymore.

> 2) A related question:  Often I find there are two ways to update the value 
> of an object, and I don't know what's best in which circumstances... To begin 
> to explain, let's say the code is within a class that represents a Frame 
> object in a GUI, like wxPython.  Now let's say ALL the code is within this 
> wxFrame class object.  So, any object that is named with "self." prepended, 
> like self.panel, or self.current_customer, or self.current_date, will be a 
> child object of that frame class, and therefore is sort of "global" to the 
> whole frame's namespace and can therefore be accessed from within any 
> function in the class. So let's say I have a function called 
> self.GetCurrentCustomer().  To actually get the name of the current customer 
> into RAM, it goes into the database and uses some rule to get the current 
> customer.  NOW, the question is, which of these should I do?  This:
>
>   def GetCurrentCustomer(self):
>   self.current_customer = #do some database stuff here
>
> Or this:
>
>   def GetCurrentCustomer(self):
>   current_customer = #do some database stuff here
>   return current_customer
>
> And what difference does it make?  In the first case, I am just updating the 
> "global" object of the current_customer, so that any function can then use 
> it.  In the second case, I am only returning the current_customer to whatever 
> function(s) call this GetCurrentCustomer() function.
>

GetCurrentCustomer should be really get_current_customer if you don't
want people screaming at you.
And about the question it depends, is the database stuff going to be expensive?
Do you need to have always a new value?

And by the way  if you're never actually using "self" in a method
maybe it should be a function, or at least a classmethod instead.

> My hunch is the first way leads to spaghetti problems.  But I want to 
> understand what the best practices are in this regard. I have found in some 
> cases the first method seemed handy, but I'm not sure what the best way of 
> thinking about this is.
>
> 3) Generally, what are other tools or approaches you would use to organize 
> well a good-sized project so to avoid fighting yourself later when you don't 
> understand your own code and the flow of information through it?  By good 
> sized, say about 20,000 lines of Python code, or something like that.
>

Good architecture and some meaningful directory structure is good
enough, to navigate Emacs + ack and I'm already very productive even
with bigger projects than that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 1.0 - release date?

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 7:54 AM, Dan Stromberg  wrote:
> Does anyone know when Python 1.0 was released?
>
> I want to say August of 1993, but there are apparently those who disagree.

Wikipedia [1] says Jan 1994, but the cited link [2] doesn't actually
give a date for 1.0. However, I did find a blog post by Guido [3] says
Jan 26 1994, uncited but presumably authoritative, and digging through
'hg log' shows this:

changeset:   1537:7ecd6380566c
branch:  legacy-trunk
user:Guido van Rossum 
date:Wed Jan 26 17:55:41 1994 +
summary: Release of 1.0.0

I'd say that's probably when it happened. :)

ChrisA

[1] https://en.wikipedia.org/wiki/History_of_Python
[2] http://www.python.org/download/releases/ (footnote 8 in the above)
[3] http://python-history.blogspot.com.au/2009/01/brief-timeline-of-python.html
-- 
https://mail.python.org/mailman/listinfo/python-list


http://bugs.python.org/user?@template=rego_progress broken?

2014-01-21 Thread Charles Hixson
I have tried to register at http://bugs.python.org, and got as far as 
this page, where I am told:
You will shortly receive an email to confirm your registration. To 
complete the registration process, visit the link indicated in the email.


But it hasn't arrived after over a day.
This case isn't too important, as I was just going to request a 
documentation change, but it happening may be more important than what I 
would have entered.


--
Charles Hixson

--
https://mail.python.org/mailman/listinfo/python-list


Re: how to avoid spaghetti in Python?

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 7:38 AM, CM  wrote:
> 1) One of my main "spaghetti problems" is something I don't know what to ever 
> call.  Basically it is that I sometimes have a "chain" of functions or 
> objects that get called in some order and these functions may live in 
> different modules and the flow of information may jump around quite a bit, 
> sometimes through 4-5 different parts of the code, and along the way 
> variables get modified (and those variables might be child objects of the 
> whole class, or they may just be objects that exist only within functions' 
> namespaces, or both).  This is hard to debug and maintain.
>

Rule of thumb: Every function should be able to be summarized in a
single line. This isn't Python-specific, but in the case of Python,
it's part of the recommendations for docstrings [1]. When one function
calls another function calls another and so on, it's not a problem if
each one can be adequately described:

def is_positive(item):
"""Ascertain whether the item is deemed positive.

Per business requirement XYZ123, items are
deemed positive at 90% certainty, even though
they are deemed negative at only 75%.
"""
return item.certainty >= 0.9 and item.state > 0

def count_positive(lst):
"""Return the number of deemed-positive items in lst."""
return sum((1 for item in lst if is_positive(item)))

Each of these functions has a clear identity. (Okay, they're a little
trivial for the sake of the example, but you can see how this would
work.) Each one makes sense on its own, and it's obvious that one
should be deferring to the other. If business requirement XYZ123 ever
changes, count_positive's behaviour should change, ergo it calls on
is_positive to make the decision.

Rule of thumb: Anything that changes state should make sense. Neither
of the above functions has any right to *modify* lst or item (except
for stats, maybe - "time since last queried" could be reset). You
mention "variables getting modified", and then go on to use some
rather non-Pythonic terminology; I'm not entirely sure what you mean
there, so I'll ignore it and just say something that may or may not
have any relevance to your case: the function's one-line summary
should normally make it clear whether state is to be changed or not. A
function that queries something shouldn't usually change that state
(except when you read from a stream; there's a bit of a grey area with
retrieving the first element of a list, which shouldn't change the
list, vs retrieving the top element of a stack/queue/heap, which
possibly should, but then you'd call it "pop" to be clear).

Tip: Adding one-line descriptions to all your functions is a great way
to figure out (or force yourself to figure out) what your code's
doing. Having someone *else* add one-line descriptions to all your
functions is an awesome way to figure out where your function names
are unclear :) I had someone go through one of my open source projects
doing exactly that, and it was quite enlightening to see which of his
docstrings were majorly incorrect. Several of them ended up triggering
renames or code revamps to make something more intuitive.

ChrisA

[1] See PEP 257, http://www.python.org/dev/peps/pep-0257/
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 1.0 - release date?

2014-01-21 Thread Dan Stromberg
Does anyone know when Python 1.0 was released?

I want to say August of 1993, but there are apparently those who disagree.

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


how to avoid spaghetti in Python?

2014-01-21 Thread CM
I've been learning and using Python for a number of years now but never really 
go particularly disciplined about all good coding practices.  I've definitely 
learned *some*, but I'm hoping this year to take a good step up in terms of 
refactoring, maintainability, and mostly just "de-spaghettizing" my approach to 
writing Python programs.  

But I could use some pointers.

Of course, many pointers will be general programming advice that is common to 
all languages, and I get that, but I also think that it's possible certain bits 
of advice are particularly relevant to Python coders, and so I ask here.  (Also 
because I know there are some great community people here who I'd enjoy getting 
their take on this).  

A few specific questions in this area...

1) One of my main "spaghetti problems" is something I don't know what to ever 
call.  Basically it is that I sometimes have a "chain" of functions or objects 
that get called in some order and these functions may live in different modules 
and the flow of information may jump around quite a bit, sometimes through 4-5 
different parts of the code, and along the way variables get modified (and 
those variables might be child objects of the whole class, or they may just be 
objects that exist only within functions' namespaces, or both).  This is hard 
to debug and maintain.  What would people recommend to manage this?  A system 
of notes?  A way to simplify the flow?  And what is this problem called (if 
something other than just spaghetti code) so I can Google more about it?

2) A related question:  Often I find there are two ways to update the value of 
an object, and I don't know what's best in which circumstances... To begin to 
explain, let's say the code is within a class that represents a Frame object in 
a GUI, like wxPython.  Now let's say ALL the code is within this wxFrame class 
object.  So, any object that is named with "self." prepended, like self.panel, 
or self.current_customer, or self.current_date, will be a child object of that 
frame class, and therefore is sort of "global" to the whole frame's namespace 
and can therefore be accessed from within any function in the class. So let's 
say I have a function called self.GetCurrentCustomer().  To actually get the 
name of the current customer into RAM, it goes into the database and uses some 
rule to get the current customer.  NOW, the question is, which of these should 
I do?  This:

  def GetCurrentCustomer(self):
  self.current_customer = #do some database stuff here

Or this:

  def GetCurrentCustomer(self):
  current_customer = #do some database stuff here
  return current_customer

And what difference does it make?  In the first case, I am just updating the 
"global" object of the current_customer, so that any function can then use it.  
In the second case, I am only returning the current_customer to whatever 
function(s) call this GetCurrentCustomer() function.

My hunch is the first way leads to spaghetti problems.  But I want to 
understand what the best practices are in this regard. I have found in some 
cases the first method seemed handy, but I'm not sure what the best way of 
thinking about this is.

3) Generally, what are other tools or approaches you would use to organize well 
a good-sized project so to avoid fighting yourself later when you don't 
understand your own code and the flow of information through it?  By good 
sized, say about 20,000 lines of Python code, or something like that.  

This is the sort of question that would be rejected on Stack Overflow, so I 
hope you can excuse my fishing for insight in a somewhat open/vague way.

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Diving in to Python - Best resources?

2014-01-21 Thread Ethan Furman

On 01/21/2014 08:00 AM, Rustom Mody wrote:


Most people -- even those using spreadsheets -- dont seem to think of
the spreadsheet macro language/VBA as a programming language


Ack, are you trying to put him off programming again?!?  ;)

Python us fun and a pleasure to use. VBA is not.  (IMNSHO & YMMV)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Modifying the default argument of function

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 6:36 AM, Mû  wrote:
> These were clear and quick answers to my problem. I did not think of this
> possibility: the default argument is created once, but accessible only by
> the function, therefore is not a global variable, whereas it looks like if
> it were at first glance.

You can actually poke at the function a bit and see what's happening.
Try this in the interactive interpreter:

>>> def f(x=[2,3]):
x.append(1)
return x

>>> f()
[2, 3, 1]
>>> f()
[2, 3, 1, 1]
>>> f.__defaults__
([2, 3, 1, 1],)

The __defaults__ attribute of a function is a tuple of its parameter
defaults. You can easily see there that the list has changed as you
changed it in the function. You could check it with id() or is, too:

>>> id(f.__defaults__[0])
24529576
>>> id(f())
24529576
>>> f() is f.__defaults__[0]
True

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x adoption

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 6:04 AM, Travis Griggs  wrote:
> I’ve had a bunch of interns around me lately though, wanting to get into 
> python, and this is where I find the momentum really breaks down. If 
> newcomers go to take an online course in python, they might try MIT’s Open 
> Courseware (who doesn’t want to learn from the illustrious MIT after all?). 
> They’ll be taught Python 2, not 3.
>

Courses are inherently laggy. I don't know how long it takes to write
a course, get it approved, and then advertise it so you get some
students, but I suspect it's a good while. I'd say that it's only
since 3.3 (some would argue 3.2, others 3.4) that Py3 has been the
clear winner in the new-application debate; give it a few more years
before courses start teaching Py3. Of course, anyone who comes to a
rapid communication venue like python-list can learn the state of the
art (in the original sense), but if you want a degree in Comp Sci and
you have to take X courses to get it, chances are you'll learn Py2
along the way.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Modifying the default argument of function

2014-01-21 Thread

Le 21/01/2014 20:19, Chris Angelico a écrit :

On Wed, Jan 22, 2014 at 6:11 AM, Mû  wrote:

The function acts as if there were a global variable x, but the call of x
results in an error (undefined variable). I don't understand why the
successive calls of f() don't return the same value: indeed, I thought that
[2,3] was the default argument of the function f, thus I expected the three
calls of f() to be exactly equivalent.


In a sense, there is. The default for the argument is simply an object
like any other, and it's stored in one place.

For cases where you want a mutable default that is "reset" every time,
the most common idiom is this:

def f(x=None):
 if x is None: x=[2,3]
 x.append(1)
 return x

That will create a new list every time, with the same initial contents.

ChrisA



Thank you, thanks everybody,

These were clear and quick answers to my problem. I did not think of 
this possibility: the default argument is created once, but accessible 
only by the function, therefore is not a global variable, whereas it 
looks like if it were at first glance.


--
Mû


---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Modifying the default argument of function

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 6:11 AM, Mû  wrote:
> The function acts as if there were a global variable x, but the call of x
> results in an error (undefined variable). I don't understand why the
> successive calls of f() don't return the same value: indeed, I thought that
> [2,3] was the default argument of the function f, thus I expected the three
> calls of f() to be exactly equivalent.

In a sense, there is. The default for the argument is simply an object
like any other, and it's stored in one place.

For cases where you want a mutable default that is "reset" every time,
the most common idiom is this:

def f(x=None):
if x is None: x=[2,3]
x.append(1)
return x

That will create a new list every time, with the same initial contents.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Modifying the default argument of function

2014-01-21 Thread emile
Function defs with mutable arguments hold a reference to the mutable 
container such that all invocations access the same changeable container.


To get separate mutable default arguments, use:

def f(x=None):
  if x is None: x=[2,3]

Emile

On 01/21/2014 11:11 AM, Mû wrote:

Hi everybody,

A friend of mine asked me a question about the following code:

[code]
def f(x=[2,3]):
 x.append(1)
 return x

print(f())
print(f())
print(f())
[/code]

The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1].

The function acts as if there were a global variable x, but the call of
x results in an error (undefined variable). I don't understand why the
successive calls of f() don't return the same value: indeed, I thought
that [2,3] was the default argument of the function f, thus I expected
the three calls of f() to be exactly equivalent.

I'm don't know much about python, does anybody have a simple explanation
please?




--
https://mail.python.org/mailman/listinfo/python-list


Re: Modifying the default argument of function

2014-01-21 Thread Steve Jones
On Tue, 21 Jan 2014 20:11:02 +0100
Mû  wrote:

> Hi everybody,
> 
> A friend of mine asked me a question about the following code:
> 
> [code]
> def f(x=[2,3]):
>  x.append(1)
>  return x
> 
> print(f())
> print(f())
> print(f())
> [/code]
> 
> The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1].
> 
> The function acts as if there were a global variable x, but the call of 
> x results in an error (undefined variable). I don't understand why the 
> successive calls of f() don't return the same value: indeed, I thought 
> that [2,3] was the default argument of the function f, thus I expected 
> the three calls of f() to be exactly equivalent.
> 
> I'm don't know much about python, does anybody have a simple explanation 
> please?

x is assigned to the list [2, 3] at the time the function is created not when 
the function is called, meaning that there's only ever 1 list created. When you 
call x.append this list is modified and the next time the function is called x 
still refers to this modified list.

-- 
https://mail.python.org/mailman/listinfo/python-list


Modifying the default argument of function

2014-01-21 Thread

Hi everybody,

A friend of mine asked me a question about the following code:

[code]
def f(x=[2,3]):
x.append(1)
return x

print(f())
print(f())
print(f())
[/code]

The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1].

The function acts as if there were a global variable x, but the call of 
x results in an error (undefined variable). I don't understand why the 
successive calls of f() don't return the same value: indeed, I thought 
that [2,3] was the default argument of the function f, thus I expected 
the three calls of f() to be exactly equivalent.


I'm don't know much about python, does anybody have a simple explanation 
please?


--
Mû

---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x adoption

2014-01-21 Thread Chris Kaynor
On Tue, Jan 21, 2014 at 11:04 AM, Travis Griggs wrote:

> Being a fan of JIT, I have big hopes for PyPy, I can’t figure out why they
> aren’t pitching their “cutting edge” interpreter, for the “cutting edge”
> version of python. There should be a wall of superpowers/shame for
> interpreters.


A very quick look at the PyPy website shows they are working on a 3.x
compatible version:
http://doc.pypy.org/en/latest/release-pypy3-2.1.0-beta1.html. Its just
still in beta.

Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x adoption

2014-01-21 Thread Travis Griggs
Looks like the 2/3 topic has lain fallow for a couple of days, gotta keep it 
burning…

I’m  a relatively recent python convert, but been coding and talking to others 
about coding for many moons on this big blue orb. I think the industrial side 
of this debate has been talked up quite a bit. We have tools, we have the wall 
of shame/superpowers for libraries and projects.

I think the desires of the core of people moving python forward are pretty 
clear to those of us that plug in. Move to 3. Period. We can debate, hate it, 
go on all day, but they’ve been pretty steady.

I’ve had a bunch of interns around me lately though, wanting to get into 
python, and this is where I find the momentum really breaks down. If newcomers 
go to take an online course in python, they might try MIT’s Open Courseware 
(who doesn’t want to learn from the illustrious MIT after all?). They’ll be 
taught Python 2, not 3. Or they might try Code Academy. Again, they’ll be 
taught 2, not 3. If the newbie googles “python reference”… top link will be 
python 2.

So in my mind, the wall of superpowers/shame is no longer well aligned with 
where the real battlefront of adoption is at. The legacy of the internet caches 
and education sites are. Personally, I have no idea why an education site would 
favor a version that sooner or later they’re going to have to try and explain 
how super() works.

The other area, I think, that puts a dent in perceived adoption is in alternate 
interpreters. Back in the day, everyone was making some branch of python (e.g. 
IronPython, Jython, Cython, PyPy, Stackless, etc). All of them did python 2. 
Very few are doing python 3. Some have been abandoned (as is the nature of 
research endeavors like these were), but there doesn’t seem to be the broad 
swath of people still building alternate python expressions, especially in 
python 3. Being a fan of JIT, I have big hopes for PyPy, I can’t figure out why 
they aren’t pitching their “cutting edge” interpreter, for the “cutting edge” 
version of python. There should be a wall of superpowers/shame for interpreters.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running pywin32-218.win32-py2.7.exe (win32 package for Python) results in error “The file exists”

2014-01-21 Thread Ziv Tepman
A small correction to my prior message:

I am trying to install the Python module "win32" but whenever I click on
the exe file (pywin32-218.win32-py2.7.exe) I get the message "The file
exists Could not create temporary file", and when I click OK, I get the
message, "*Setup program invalid or damaged*." I have chosen the
appropriate build. How might I fix this error?  Thanks!


On Tue, Jan 21, 2014 at 10:02 AM, Ziv Tepman  wrote:

> I am trying to install the Python module "win32" but whenever I click on
> the exe file (pywin32-218.win32-py2.7.exe) I get the message "The file
> exists Could not create temporary file", and when I click OK, I get the
> message, "pywin32-218.win32-py2.7." I have chosen the appropriate build.
> How might I fix this error?  Thanks!
>
-- 
https://mail.python.org/mailman/listinfo/python-list


A day of free Python & Django talks & tutorials, Cardiff (UK)

2014-01-21 Thread D.M. Procida
Django Weekend Cardiff  is completely sold
out.

Our open day remains open however, and you're invited to attend the
numerous talks, tutorials and demonstrations in the programme. They'll
all be held at Cardiff University.



There are fifteen different sessions in the open day programme, on all
kinds of subjects - from medicine to robotics - and at various levels of
technical complexity.

One of the key audiences for the open day is developers who want to
learn more about Python and Django  so if that's you, you're especially
welcome.

Another key audience is A-level science pupils and teachers, and we have
a number of talks that have been devised with them in mind - so if you
know any, please point them in our direction, as we'll be very pleased
to see them.

All the sessions are free, and refreshments will be provided.

Registration is required so we know how many people to expect, and
places in the tutorials will be limited.

The sooner you register the better it is for us, because we have to plan
catering, access and other practicalities - so please do it as soon as
you can!

Register: 

And finally, do pass on details of the open day to anyone else whom you
think might be interested.

Thanks,

Daniele
-- 
Django Weekend Cardiff, the first-ever Django conference in the UK
Three days of Django/Python talks, tutorials and code sprints


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Add followers at time of import

2014-01-21 Thread emile

On 01/21/2014 10:03 AM, Chris Angelico wrote:

On Wed, Jan 22, 2014 at 4:52 AM, emile  wrote:



Ask if that's not clear.


I'm not entirely sure, but I think this might have been meant for
somewhere other than python-list. Welcome to the club.


Aargh! -- I hate when that happens... Sorry.

Emile



--
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Peter Otten
Robert Voigtländer wrote:

> 
>> > > def pop(self):
>> > > f, node = heapq.heappop()
>> > > del lookup[node.pos]
>> > > return node
> 
>> > That should be
>> 
>> > def pop(self):
>> 
>> > f, node = heapq.heappop(self.heap)
>> > del self.lookup[node.pos]
>> > return node
>> 
>> Hi Peter,
>> this works great. I will try to find some info about the functionality
>> you used and to understnad what you did. Maybe you can add a function to
>> remove a node? Thanks for your support and all tthe swift answers.
>> 
>> Robert
> 
> Just realized what the pop function is for. I changed it from:
> def pop(self):
> to
> def pop(self,pos):
> 
> and it works.

Unlikely. Are you sure that .heap and .lookup contents are still in sync 
with your modification?

> Now I go on with trying to understand it.

The pop() method as posted can only remove the "lowest" node. If contrary to 
your initial spec

> 2. find the object with the lowest Node.f attribute and update or remove 
it

you want to remove arbitrary nodes a heap may not be the appropriate data 
structure. The modified

import operator

#...

class Nodes():
def __init__(self):
self.lookup = {}
def add(self, node):
self.lookup[node.pos] = node
def __iter__(self):
return iter(self.lookup.itervalues())
def __contains__(self, pos):
return pos in self.lookup
def lowest(self):
return min(self, key=operator.attrgetter("f"))
def __delitem__(self, pos):
del self.lookup[pos]

nodes = Nodes()

nodes.add(Node((1,1), None, 1, 5))
nodes.add(Node((1,2), (1,1), 4, 6))
nodes.add(Node((1,3), (1,2), 9, 10))

del nodes[1, 2]


allows you to delete random nodes, but the lowest() method will slow down as 
it has to iterate over all dict values.

One important caveat: both Nodes classes lead to data corruption if you 
modify a .pos attribute while the node is in a Nodes instance. The same goes 
for the first implementation and the .f attribute.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Add followers at time of import

2014-01-21 Thread Ethan Furman

On 01/21/2014 10:03 AM, Chris Angelico wrote:

On Wed, Jan 22, 2014 at 4:52 AM, emile wrote:


Ask if that's not clear.


I'm not entirely sure, but I think this might have been meant for
somewhere other than python-list. Welcome to the club.


And it's an elite club, too!  Very few members.  ;)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: import file without .py into another module

2014-01-21 Thread Mark Lawrence

On 21/01/2014 15:50, kevinber...@gmail.com wrote:

[snipped the double line spaced stuff courtesy of google]

Would you please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing that google inserts, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Add followers at time of import

2014-01-21 Thread emile

Hi Ethan,

How hard would it be to add a follower to a transaction (PO or Sales 
Order) at time of import if the account has that follower?  IOW, Ron 
follows 'hilltop ranch' -- he'd like all activity linked to 'hilltop 
ranch' to include him as a follower.  Right now, following the account 
doesn't notify about changes to documents, only changes to the account 
itself.


Ask if that's not clear.

Emile


--
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Mark Lawrence

On 21/01/2014 13:43, Robert Voigtländer wrote:

[double spaced google disease snipped]

I'm pleased to see the regular contributors helping out as usual.  In 
response would you please be kind enough to read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing that google inserts, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Running pywin32-218.win32-py2.7.exe (win32 package for Python) results in error “The file exists”

2014-01-21 Thread Ziv Tepman
I am trying to install the Python module "win32" but whenever I click on
the exe file (pywin32-218.win32-py2.7.exe) I get the message "The file
exists Could not create temporary file", and when I click OK, I get the
message, "pywin32-218.win32-py2.7." I have chosen the appropriate build.
How might I fix this error?  Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Add followers at time of import

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 4:52 AM, emile  wrote:
> Hi Ethan,
>
> How hard would it be to add a follower to a transaction (PO or Sales Order)
> at time of import if the account has that follower?  IOW, Ron follows
> 'hilltop ranch' -- he'd like all activity linked to 'hilltop ranch' to
> include him as a follower.  Right now, following the account doesn't notify
> about changes to documents, only changes to the account itself.
>
> Ask if that's not clear.

I'm not entirely sure, but I think this might have been meant for
somewhere other than python-list. Welcome to the club.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Diving in to Python - Best resources?

2014-01-21 Thread Terry Reedy

On 1/21/2014 11:00 AM, Rustom Mody wrote:

On Tuesday, January 21, 2014 1:04:16 AM UTC+5:30, Matt Watson wrote:

Getting in the habit of dropping in a google group for any new project -
everyone tends to be so helpful.



I work in the automotive sales industry(management) and find myself
doing so many day to day tasks that could easily be automated. I'm a
very tech saavy person, but after running in fear from a Javascript
class in undergrad 8 years ago I haven't ever looked back. I simply
had no interest because I saw no applications.



Now that I have a solid career I see SO many applications for
programming in my industry alone. Automating data
movement/calculations from websites, spreadsheets, pricing, etc will
be my primary use.I'm OK saying I didn't retain 1% of what I
learned in the Javascript class, I've dabbled in HTML, I've tweaked
code in Excel macros or AutoIt scripts, but I'd classify myself as a
complete beginner in programming.


It looks like
1. You are familiar with spreadsheets
2. Your work is spreadsheet-like

Why not develop that into a bigger strength?

Most people -- even those using spreadsheets -- dont seem to think of
the spreadsheet macro language/VBA as a programming language but it
is


Definitely. I once worked out how to do nonlinear regression with a 
spreadsheet, after doing it with Basic (and later C).



and it may well be all you need. This is written by one of the
biggest names in programming languages today

http://research.microsoft.com/en-us/um/people/simonpj/Papers/excel/excel.pdf


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


autoconf tools and python3 3m 3dm

2014-01-21 Thread Mark Heieis

Hi,

I've been migrating a python2 package+extension to python3. The problem 
I'm running into is with ./configure and which version it picks up or 
doesn't in this case.


The default is python2 and works just fine as expected.

However, when ./configure PYTHON=python3 is run, the problems occur. 
"./configure" picks python3 correctly and propagates that through to all 
of the makefiles created. Good so far. It defines all of the appropriate 
libs and include with the '3.3' extension.


The yum installed python3, however, is denoted by a suffix 'dm', 
yielding an extension of '3.3dm' (Fedora 20)
Building and installing from source, python has a suffix 'm', so the 
extension is '3.3m;


In ./configure, PYTHON_VERSION is set by "$PYTHON -c 'import sys; 
print(sys.version[:3])'" which reports "3.3". PYTHON_VERSION is then 
used as the suffix to find all of the appropriate python directories, 
libraries, site-packages and includes. The same result is had if 
python3.3m or python3.3dm is used.


Unfortunately, this isn't enough, as the python site packages are 
installed with naming ending in 'm' or 'dm', resulting in all of the 
makefiles failing because they can't find the libraries, include files, 
or site packages.


I've kludged a solution by manually creating soft links in the lib and 
include directories which almost solves the problem:


for example in /usr/lib64:

lrwxrwxrwx.  1 root root  19 2013-12-18 15:02 libpython2.7.so -> 
libpython2.7.so.1.0

-r-xr-xr-x.  1 root root 1800480 2013-11-12 08:47 libpython2.7.so.1.0
lrwxrwxrwx   1 root root  21 2014-01-20 16:11 libpython3.3dm.so -> 
libpython3.3dm.so.1.0

-rwxr-xr-x   1 root root 3057640 2013-11-07 02:03 libpython3.3dm.so.1.0
lrwxrwxrwx   1 root root  20 2014-01-20 16:11 libpython3.3m.so -> 
libpython3.3m.so.1.0

-rwxr-xr-x   1 root root 2498992 2013-11-07 02:03 libpython3.3m.so.1.0
lrwxrwxrwx   1 root root  20 2014-01-20 16:37 libpython3.3.so -> 
libpython3.3m.so.1.0

-rwxr-xr-x   1 root root6704 2013-11-07 02:03 libpython3.so

This approach doesn't feel right to me.  I don't think pythonX.Y-config 
would work either as one would need to know in advance specifically 
which one to call and there'd be extra work to extract the full version 
info, etc. ("$python3-config --includes" yields 
-I/usr/include/python3.3m -I/usr/include/python3.3m)


Has anyone else come up against this? If so, what was the solution?

BTW - anyone know what the 'm' and 'dm' suffixes indicate?

TIA.






--
https://mail.python.org/mailman/listinfo/python-list


Re: Early retirement project?

2014-01-21 Thread Terry Reedy

On 1/21/2014 6:38 AM, Tim Chase wrote:

On 2014-01-21 00:00, xeysx...@gmail.com wrote:

Well, I retired early, and I guess now I've got some spare time to
learn about programming, which always seemed rather mysterious. I
am using an old mac as my main computer, and it runs os x 10.4 is
this too old? It fills my needs, and I am on a fixed income and
can't really afford to buy another. I think python would be a good
starter language, based on what I've read on the net.


It's certainly a great way to consume lots of hours :)

Mac OS X 10.4 should come with an older version of Python
out-of-the-box.


Someone else said that it comes with 2.5. That will be fine for many 
purposed. If you do use that, always make any classes you define a 
subclass of 'object' if nothing else. In other words,


class MyClass(object): ...
# instead of
class MyClass: ...

In Python 2, the second gives you an 'old-style' or 'classic' class. You 
do not need to learn about those. In Python 3, both forms give you 
new-style classes, which is what you should learn.


There are a few other obsolete features to avoid, such as using strings 
for exceptions.



The install media should also include XCode if you
want to download the latest & greatest version of Python and install
that from source instead.


If you can do that easily, I recommend starting with the latest Python 
3, especially if you want to work with non-English (non-ascii) characters.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Diving in to Python - Best resources?

2014-01-21 Thread Rustom Mody
On Tuesday, January 21, 2014 1:04:16 AM UTC+5:30, Matt Watson wrote:
> Getting in the habit of dropping in a google group for any new project - 
> everyone tends to be so helpful.

> I work in the automotive sales industry(management) and find myself
> doing so many day to day tasks that could easily be automated. I'm a
> very tech saavy person, but after running in fear from a Javascript
> class in undergrad 8 years ago I haven't ever looked back. I simply
> had no interest because I saw no applications.

> Now that I have a solid career I see SO many applications for
> programming in my industry alone. Automating data
> movement/calculations from websites, spreadsheets, pricing, etc will
> be my primary use.I'm OK saying I didn't retain 1% of what I
> learned in the Javascript class, I've dabbled in HTML, I've tweaked
> code in Excel macros or AutoIt scripts, but I'd classify myself as a
> complete beginner in programming.

It looks like 
1. You are familiar with spreadsheets
2. Your work is spreadsheet-like

Why not develop that into a bigger strength?

Most people -- even those using spreadsheets -- dont seem to think of
the spreadsheet macro language/VBA as a programming language but it
is and it may well be all you need.  This is written by one of the
biggest names in programming languages today

http://research.microsoft.com/en-us/um/people/simonpj/Papers/excel/excel.pdf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import file without .py into another module

2014-01-21 Thread kevinbercaw
On Tuesday, January 21, 2014 10:40:09 AM UTC-5, Peter Otten wrote:
> kevin...@gmail.com wrote:
> 
> 
> 
> >> > How do I get the value of the config file variable "myVar"??  It seems
> 
> >> > it's interpreting the variable name as a string rather than a variable
> 
> >> > name.  I don't see any python function stringToVariable.
> 
> 
> 
> >> The line:
> 
> >> 
> 
> >>  configModuleObject = imp.load_source(fileName, filePath)
> 
> 
> 
> >> imports the module and then binds it to the name configModuleObject,
> 
> >> 
> 
> >> therefore:
> 
> >> 
> 
> >>  print configModuleObject.myVar
> 
> > 
> 
> > Yep, I tried that right off as that's how I thought it would work, but it
> 
> > doesn't work. Traceback (most recent call last):
> 
> >   File "mainScript.py", line 31, in 
> 
> > print configModuleObject.myVar
> 
> > AttributeError: 'module' object has no attribute 'myVar'
> 
> 
> 
> Try again with
> 
> 
> 
> module = imp.load_source("made_up_name", "a15800")
> 
> print module.myVar
> 
> 
> 
> If the file "a15800" is not in the current working directory, give the 
> 
> complete path, e. g:
> 
> 
> 
> module = imp.load_source("made_up_name", "/path/to/a15800")
> 
> print module.myVar
> 
> 
> 
> The first arg serves as the module's name which is used for caching to speed 
> 
> up repeated imports:
> 
> 
> 
> >>> import imp
> 
> >>> import sys
> 
> >>> "made_up_name" in sys.modules
> 
> False
> 
> >>> module = imp.load_source("made_up_name", "a15800")
> 
> >>> module.myVar
> 
> 'hello'
> 
> >>> "made_up_name" in sys.modules
> 
> True
> 
> >>> module
> 
> 

Thanks Peter Otten, that worked.  I was not able to understand the 
documentation for imp.load_source correctly.  Thanks so much!
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: rom 0.25.0 - Redis object mapper for Python

2014-01-21 Thread Josiah Carlson
Hey everyone,

Big change today: rom now supports fast prefix, suffix, and pattern match
queries over your data. The method is based on the autocomplete process
described in my book, Redis in Action

The "rom" package is a Redis object mapper for Python. It sports an
interface similar to Django's ORM, SQLAlchemy + Elixir, or Appengine's
datastore.

The changelog for recent releases can be seen below my signature.

You can find the package at:
https://www.github.com/josiahcarlson/rom
https://pypi.python.org/pypi/rom

And docs can be found at:
http://pythonhosted.org/rom/

Please CC me on any replies if you have any questions or comments.

Thank you,
 - Josiah

#-- 0.25.0
---
[changed] version numbers to account for bugfixes vs. feature updates.
[added] columns can now be defined to allow for prefix and/or suffix
queries.
Enabling prefix queries also enables arbitrary pattern matching over
your
data.
[fixed] in some cases, rom would allow the definition of multiple primary
keys, of which only one would ever be used (inconsistently). This will
now
result in an error.
[changed] defaulted to assume Lua is available on Redis, which has been
released for over 15 months at this point. You can disable support via
a call to rom._disable_lua_writes().
[added] the ability to cache and get the key that holds the result of a
query,
which can be used for pagination, etc. See: Query.cached_result()
[warning] using rom versions of 0.23 with 0.25.0 when prefix and suffix
indexes are enabled can result in improper results from prefix, suffix,
and/or pattern queries, and can result in orphan data living in prefix
or
suffix indexes. Upgrade all of your clients!
[changed] temporary keys for queries are now prefixed with the name of the
model over which queries are being executed on. This should effect
basically zero people, but can allow for query cleanup in the off chance
of a failure during execution.
#- 0.23 (unreleased)
-
[changed] reduced number of round trips for single-filter queries by 1,
thanks
to https://github.com/MickeyKim for the report.
#--- 0.22

[fixed] size estimation for intersection ordering when filtering has now
been
fixed, thank you to https://github.com/MickeyKim for the report and the
change (should improve performance).
[fixed] an issue with some types when trying to update attributes has now
been
fixed, thank you to https://github.com/denisvolokh for the report.
[changed] improved performance for simple numeric range queries of the form
Model.get_by(attr=value) or Model.get_by(attr=(min, max)) by roughly a
factor of 60x or better in some cases. Thank you to
https://github.com/MickeyKim for the report on poor performance.
#--- 0.21

[fixed] upload for rom 0.20 was missing new columns.py, now fixed
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer

> > > def pop(self):
> > > f, node = heapq.heappop()
> > > del lookup[node.pos]
> > > return node

> > That should be
> 
> > def pop(self):
> 
> > f, node = heapq.heappop(self.heap)
> > del self.lookup[node.pos]
> > return node
> 
> Hi Peter,
> this works great. I will try to find some info about the functionality you 
> used and to understnad what you did.
> Maybe you can add a function to remove a node?
> Thanks for your support and all tthe swift answers.
> 
> Robert

Just realized what the pop function is for. I changed it from:
def pop(self):
to
def pop(self,pos):

and it works.

Now I go on with trying to understand it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
Am Dienstag, 21. Januar 2014 15:19:54 UTC+1 schrieb Peter Otten:
> Peter Otten wrote:
> 
> 
> 
> > def pop(self):
> 
> > f, node = heapq.heappop()
> 
> > del lookup[node.pos]
> 
> > return node
> 
> 
> 
> That should be
> 
> 
> 
> def pop(self):
> 
> f, node = heapq.heappop(self.heap)
> 
> del self.lookup[node.pos]
> 
> return node

Hi Peter,

this works great. I will try to find some info about the functionality you used 
and to understnad what you did.
Maybe you can add a function to remove a node?

Thanks for your support and all tthe swift answers.

Robert
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import file without .py into another module

2014-01-21 Thread Tim Chase
On 2014-01-21 07:13, kevinber...@gmail.com wrote:
>On Tuesday, January 21, 2014 10:06:16 AM UTC-5, MRAB wrote:
>>  configModuleObject = imp.load_source(fileName, filePath)
>> 
>> imports the module and then binds it to the name
>> configModuleObject,
>> 
>> therefore:
>>
>>  print configModuleObject.myVar
> 
> Yep, I tried that right off as that's how I thought it would work,
> but it doesn't work. Traceback (most recent call last):
>   File "mainScript.py", line 31, in 
> print configModuleObject.myVar
> AttributeError: 'module' object has no attribute 'myVar'

Check what you're passing for fileName/FilePath:

 >>> import imp
 >>> with open('demo.txt', 'wb') as f:
 ... f.write('x = 42\ny = "hello"\n')
 ... 
 >>> d = imp.load_source('SomeName', 'demo.txt')
 >>> dir(d)
 ['__builtins__', '__doc__', '__file__', '__name__', '__package__',
 'x', 'y']
 >>> d.x
 42
 >>> d.y
 'hello'
 >>> d.__name__
 'SomeName'

-tkc




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import file without .py into another module

2014-01-21 Thread Peter Otten
kevinber...@gmail.com wrote:

>> > How do I get the value of the config file variable "myVar"??  It seems
>> > it's interpreting the variable name as a string rather than a variable
>> > name.  I don't see any python function stringToVariable.

>> The line:
>> 
>>  configModuleObject = imp.load_source(fileName, filePath)

>> imports the module and then binds it to the name configModuleObject,
>> 
>> therefore:
>> 
>>  print configModuleObject.myVar
> 
> Yep, I tried that right off as that's how I thought it would work, but it
> doesn't work. Traceback (most recent call last):
>   File "mainScript.py", line 31, in 
> print configModuleObject.myVar
> AttributeError: 'module' object has no attribute 'myVar'

Try again with

module = imp.load_source("made_up_name", "a15800")
print module.myVar

If the file "a15800" is not in the current working directory, give the 
complete path, e. g:

module = imp.load_source("made_up_name", "/path/to/a15800")
print module.myVar

The first arg serves as the module's name which is used for caching to speed 
up repeated imports:

>>> import imp
>>> import sys
>>> "made_up_name" in sys.modules
False
>>> module = imp.load_source("made_up_name", "a15800")
>>> module.myVar
'hello'
>>> "made_up_name" in sys.modules
True
>>> module



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Early retirement project?

2014-01-21 Thread Grant Edwards
On 2014-01-21, Larry Martell  wrote:
> On Tue, Jan 21, 2014 at 1:30 AM, Devin Jeanpierre
> wrote:
>> Congrats on the early retirement! It takes guts to decide to do that. :)
>
> I thought it took money.

One or the other.  If you've got money, it doesn't take guts.

-- 
Grant Edwards   grant.b.edwardsYow! I feel better about
  at   world problems now!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use class in class

2014-01-21 Thread Robert Voigtländer
> 
>  copy/paste of the whole thing. The actual error message could not
> 
>  have said "node", as there's no such name in the method.
> 

You are correct. I copied the error before I renamed node into Node. I have to 
be more consistent here. :-)
The source for the error was still the same.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import file without .py into another module

2014-01-21 Thread kevinbercaw
On Tuesday, January 21, 2014 9:44:13 AM UTC-5, kevin...@gmail.com wrote:
> I have a python script that accepts two arguments:
> 
> sys.argv[1] is the full directory path to a config script.  The script is 
> python but does not have a .py extension!
> 
> sys.argv[2] is the file name of the config script
> 
> 
> 
> For example:
> 
> mainScript.py ./ a15800
> 
> 
> 
> 
> 
> The config script sets variables that I want to be able to use in the main 
> script.
> 
> 
> 
> *** contents of "a15800": ***
> 
> myVar = "hello"
> 
> 
> 
> *** contents of "mainScript.py": ***
> 
> def printVars(configModuleName):
> 
> myVarName = ("%s.myVar" % configModuleName)
> 
> print "myVarName = %s" % myVarName
> 
> myVarValue = eval(myVarName)
> 
> print "myVarValue = %s" % myVarValue
> 
> 
> 
> 
> 
> if __name__ == '__main__':
> 
> import sys
> 
> import imp
> 
> filePath = sys.argv[1]
> 
> fileName = sys.argv[2]
> 
> configModuleObject = imp.load_source(fileName, filePath)
> 
> configModuleName = configModuleObject.__name__
> 
> print "configModuleName = %s" % configModuleName
> 
> printVars(configModuleName)
> 
> 
> 
> *** Output: ***
> 
> >mainScript.py ./ a15800
> 
> configModuleName = a15800
> 
> myVarName = a15800.myVar
> 
> Traceback (most recent call last):
> 
>   File "mainScript.py", line 27, in 
> 
> printVars(configModuleName)
> 
>   File "mainScript.py", line 15, in printVars
> 
> myVarValue = eval(myVarName)
> 
>   File "", line 1, in 
> 
> NameError: name 'a15800' is not defined
> 
> 
> 
> *** Question: ***
> 
> How do I get the value of the config file variable "myVar"??  It seems it's 
> interpreting the variable name as a string rather than a variable name.  I 
> don't see any python function stringToVariable.

FYI - more info from interactive session, query configModuleObject and 
configModuleName using imp.find_module:
>>> imp.find_module("configModuleObject")
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named configModuleObject
>>> imp.find_module("a15800")
(, 'a15800.pyc', ('.pyc', 
'rb', 2))
>>> imp.find_module(configModuleName)
(, 'a15800.pyc', ('.pyc', 
'rb', 2))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import file without .py into another module

2014-01-21 Thread kevinbercaw
On Tuesday, January 21, 2014 10:06:16 AM UTC-5, MRAB wrote:
> On 2014-01-21 14:44,  wrote:
> 
> > I have a python script that accepts two arguments:
> 
> > sys.argv[1] is the full directory path to a config script.  The script is 
> > python but does not have a .py extension!
> 
> > sys.argv[2] is the file name of the config script
> 
> >
> 
> > For example:
> 
> > mainScript.py ./ a15800
> 
> >
> 
> >
> 
> > The config script sets variables that I want to be able to use in the main 
> > script.
> 
> >
> 
> > *** contents of "a15800": ***
> 
> > myVar = "hello"
> 
> >
> 
> > *** contents of "mainScript.py": ***
> 
> > def printVars(configModuleName):
> 
> >  myVarName = ("%s.myVar" % configModuleName)
> 
> >  print "myVarName = %s" % myVarName
> 
> >  myVarValue = eval(myVarName)
> 
> >  print "myVarValue = %s" % myVarValue
> 
> >
> 
> >
> 
> > if __name__ == '__main__':
> 
> >  import sys
> 
> >  import imp
> 
> >  filePath = sys.argv[1]
> 
> >  fileName = sys.argv[2]
> 
> >  configModuleObject = imp.load_source(fileName, filePath)
> 
> >  configModuleName = configModuleObject.__name__
> 
> >  print "configModuleName = %s" % configModuleName
> 
> >  printVars(configModuleName)
> 
> >
> 
> > *** Output: ***
> 
> >>mainScript.py ./ a15800
> 
> > configModuleName = a15800
> 
> > myVarName = a15800.myVar
> 
> > Traceback (most recent call last):
> 
> >File "mainScript.py", line 27, in 
> 
> >  printVars(configModuleName)
> 
> >File "mainScript.py", line 15, in printVars
> 
> >  myVarValue = eval(myVarName)
> 
> >File "", line 1, in 
> 
> > NameError: name 'a15800' is not defined
> 
> >
> 
> > *** Question: ***
> 
> > How do I get the value of the config file variable "myVar"??  It seems it's 
> > interpreting the variable name as a string rather than a variable name.  I 
> > don't see any python function stringToVariable.
> 
> >
> 
> The line:
> 
> 
> 
>  configModuleObject = imp.load_source(fileName, filePath)
> 
> 
> 
> imports the module and then binds it to the name configModuleObject,
> 
> therefore:
> 
> 
> 
>  print configModuleObject.myVar

Yep, I tried that right off as that's how I thought it would work, but it 
doesn't work.
Traceback (most recent call last):
  File "mainScript.py", line 31, in 
print configModuleObject.myVar
AttributeError: 'module' object has no attribute 'myVar'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import file without .py into another module

2014-01-21 Thread MRAB

On 2014-01-21 14:44, kevinber...@gmail.com wrote:

I have a python script that accepts two arguments:
sys.argv[1] is the full directory path to a config script.  The script is 
python but does not have a .py extension!
sys.argv[2] is the file name of the config script

For example:
mainScript.py ./ a15800


The config script sets variables that I want to be able to use in the main 
script.

*** contents of "a15800": ***
myVar = "hello"

*** contents of "mainScript.py": ***
def printVars(configModuleName):
 myVarName = ("%s.myVar" % configModuleName)
 print "myVarName = %s" % myVarName
 myVarValue = eval(myVarName)
 print "myVarValue = %s" % myVarValue


if __name__ == '__main__':
 import sys
 import imp
 filePath = sys.argv[1]
 fileName = sys.argv[2]
 configModuleObject = imp.load_source(fileName, filePath)
 configModuleName = configModuleObject.__name__
 print "configModuleName = %s" % configModuleName
 printVars(configModuleName)

*** Output: ***

mainScript.py ./ a15800

configModuleName = a15800
myVarName = a15800.myVar
Traceback (most recent call last):
   File "mainScript.py", line 27, in 
 printVars(configModuleName)
   File "mainScript.py", line 15, in printVars
 myVarValue = eval(myVarName)
   File "", line 1, in 
NameError: name 'a15800' is not defined

*** Question: ***
How do I get the value of the config file variable "myVar"??  It seems it's 
interpreting the variable name as a string rather than a variable name.  I don't see any 
python function stringToVariable.


The line:

configModuleObject = imp.load_source(fileName, filePath)

imports the module and then binds it to the name configModuleObject,
therefore:

print configModuleObject.myVar

--
https://mail.python.org/mailman/listinfo/python-list


import file without .py into another module

2014-01-21 Thread kevinbercaw
I have a python script that accepts two arguments:
sys.argv[1] is the full directory path to a config script.  The script is 
python but does not have a .py extension!
sys.argv[2] is the file name of the config script

For example:
mainScript.py ./ a15800


The config script sets variables that I want to be able to use in the main 
script.

*** contents of "a15800": ***
myVar = "hello"

*** contents of "mainScript.py": ***
def printVars(configModuleName):
myVarName = ("%s.myVar" % configModuleName)
print "myVarName = %s" % myVarName
myVarValue = eval(myVarName)
print "myVarValue = %s" % myVarValue


if __name__ == '__main__':
import sys
import imp
filePath = sys.argv[1]
fileName = sys.argv[2]
configModuleObject = imp.load_source(fileName, filePath)
configModuleName = configModuleObject.__name__
print "configModuleName = %s" % configModuleName
printVars(configModuleName)

*** Output: ***
>mainScript.py ./ a15800
configModuleName = a15800
myVarName = a15800.myVar
Traceback (most recent call last):
  File "mainScript.py", line 27, in 
printVars(configModuleName)
  File "mainScript.py", line 15, in printVars
myVarValue = eval(myVarName)
  File "", line 1, in 
NameError: name 'a15800' is not defined

*** Question: ***
How do I get the value of the config file variable "myVar"??  It seems it's 
interpreting the variable name as a string rather than a variable name.  I 
don't see any python function stringToVariable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Peter Otten
Peter Otten wrote:

> def pop(self):
> f, node = heapq.heappop()
> del lookup[node.pos]
> return node

That should be

def pop(self):
f, node = heapq.heappop(self.heap)
del self.lookup[node.pos]
return node


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Peter Otten
Robert Voigtländer wrote:

> 
>> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote:
>> 
> 
>> > I have objects like this:
>> 
>> > 
>> 
>> > class Node(object):
>> 
>> > def __init__(self, pos, parent, g , h):
>> 
>> > self.pos = pos
>> 
>> > self.parent = parent
>> 
>> > self.g = g
>> 
>> > self.h = h
>> 
>> > self.f = g+h
>> 
>> > 
>> 
>> > 
>> 
>> > I need to build a "list" of these objects. The amount is unknown.
>> 
>> > On this list I need to regularly
>> 
>> > 
>> 
>> > 1. check if a specific item - identified by Node.pos - is in the list.
>> 
>> > 2. find the object with the lowest Node.f attribute and update or
>> > remove it
>> 
> 
> 
> First thanks to all who responded. Although I only partially understand
> your answers as I am a Python starter. What's clear to me is the
> difference between object and instance of an object. Just didn't explain
> it well.
> 
> Maybe I give some more info on what I need / want to do. I will also
> provide a working code example. Should have done this before.
> 
> I would very much appreciate a working example of what you mean. Then I
> have a chance to understand it. :-)
> 
> I would like to implement a class for a A* pathfinding algorithm. (there
> are ready libraries out there but I would like to learn it myself) This
> requires to maintain a list of nodes to be processed and nodes already
> processed. For new nodes I need to check if they are on one of the lists.
> I also need to regularly pick the node with the lowest value f from the
> list.
> 
> Here some working code. For one function I sill need a solution. Any
> better solution is welcome.
> 
> Thanks
> Robert
> 
> ---
> class Node:
> def __init__(self, pos, parent, g , h):
> self.pos = pos
> self.parent = parent
> self.g = g
> self.h = h
> self.f = g+h
> 
> 
> def isinlist(nodeToSeatch):
> for item in openlist:
> if item.pos == nodeToSeatch: return True
> return False
> 
> 
> def lowestF():
> lowestF = ''
> for item in openlist:
> if item.f < lowestF: lowestF = item
> return lowestF

def lowestF():
return min(openlist, key=operator.attrgetter("f"))

 
> def deleteItemWithPos(pos):
> ## need this function or different approach
> pass
> 
> openlist=[]
> openlist.append(Node((1,1),None,1,5))
> openlist.append(Node((1,2),(1,1),4,6))
> openlist.append(Node((1,3),(1,2),9,10))
> 
> for item in openlist: print item.pos, item.f
> 
> print isinlist((1,1))
> print isinlist((1,5))
> 
> nextNode = lowestF()
> print nextNode.pos, nextNode.f

Here is an OO implementation of Chris Angelico's suggestion:

import heapq

class Node:
def __init__(self, pos, parent, g , h):
self.pos = pos
self.parent = parent
self.g = g
self.h = h
self.f = g+h
def __str__(self):
return "Node(pos={!r}, f={!r})".format(self.pos, self.f)

class Nodes():
def __init__(self):
self.lookup = {}
self.heap = []
def add(self, node):
self.lookup[node.pos] = node
heapq.heappush(self.heap, (node.f, node))
def __iter__(self):
return iter(self.lookup.values())
def __contains__(self, pos):
return pos in self.lookup
def lowest(self):
return self.heap[0][1]
def pop(self):
f, node = heapq.heappop()
del lookup[node.pos]
return node

nodes = Nodes()
nodes.add(Node((1,1), None, 1, 5))
nodes.add(Node((1,2), (1,1), 4, 6))
nodes.add(Node((1,3), (1,2), 9, 10))

for node in nodes:
print(node)

print((1,1) in nodes)
print((1,5) in nodes)

print(nodes.lowest())





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Oscar Benjamin
On Tue, Jan 21, 2014 at 05:38:34AM -0800, Robert Voigtländer wrote:
> 
> > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote:
> > 
> 
> > > I have objects like this:
> > 
> > > 
> > 
> > > class Node(object): 
> > 
> > > def __init__(self, pos, parent, g , h): 
> > 
> > > self.pos = pos 
> > 
> > > self.parent = parent 
> > 
> > > self.g = g 
> > 
> > > self.h = h 
> > 
> > > self.f = g+h 
> > 
> > > 
> > 
> > > 
> > 
> > > I need to build a "list" of these objects. The amount is unknown.
> > 
> > > On this list I need to regularly
> > 
> > > 
> > 
> > > 1. check if a specific item - identified by Node.pos - is in the list.
> > 
> > > 2. find the object with the lowest Node.f attribute and update or remove 
> > > it
> > 
> 
> 
> First thanks to all who responded. Although I only partially understand your 
> answers as I am a Python starter.
> What's clear to me is the difference between object and instance of an 
> object. Just didn't explain it well.  
> 
> Maybe I give some more info on what I need / want to do. I will also provide 
> a working code example. Should have done this before.
> 
> I would very much appreciate a working example of what you mean. Then I have 
> a chance to understand it. :-)
> 
> I would like to implement a class for a A* pathfinding algorithm. (there are 
> ready libraries out there but I would like to learn it myself) This requires 
> to maintain a list of nodes to be processed and nodes already processed. For 
> new nodes I need to check if they are on one of the lists. I also need to 
> regularly pick the node with the lowest value f from the list.
> 
> Here some working code. For one function I sill need a solution. Any better 
> solution is welcome.
> 
> Thanks
> Robert
> 
> ---
> class Node:
> def __init__(self, pos, parent, g , h):
> self.pos = pos
> self.parent = parent
> self.g = g
> self.h = h
> self.f = g+h
> 
> 
> def isinlist(nodeToSeatch):
> for item in openlist:
> if item.pos == nodeToSeatch: return True
> return False
> 
> 
> def lowestF():
> lowestF = ''
> for item in openlist:
> if item.f < lowestF: lowestF = item
> return lowestF

The function above is incorrect. I think it should be:

 def lowestF():
 lowestF = ''
 for item in openlist:
 if item.f < lowestF:
lowestF = item.f  # Note the .f here
 return lowestF

> 
> def deleteItemWithPos(pos):
> ## need this function or different approach
> pass

def deleteItemWithPos(pos):
for n, item in enumerate(openlist):
if item.pos == pos:
del openlist[n]
return
else:
raise RuntimeError('Not in the list!')


> 
> openlist=[]
> openlist.append(Node((1,1),None,1,5))
> openlist.append(Node((1,2),(1,1),4,6))
> openlist.append(Node((1,3),(1,2),9,10))
> 
> for item in openlist: print item.pos, item.f
> 
> print isinlist((1,1))
> print isinlist((1,5))
> 
> nextNode = lowestF()
> print nextNode.pos, nextNode.f

My first suggestion would be to use a dict instead of a list:


class Node:
def __init__(self, pos, parent, g , h):
self.pos = pos
self.parent = parent
self.g = g
self.h = h
self.f = g+h

def isinlist(pos):
return pos in opendict

def lowestF():
return min(opendict.values(), key=lambda x: x.f)

def deleteItemWithPos(pos):
del opendict[pos]

nodes = [
Node((1,1),None,1,5),
Node((1,2),(1,1),4,6),
Node((1,3),(1,2),9,10),
]

opendict = {}
for node in nodes:
opendict[node.pos] = node

for item in opendict.values():
print item.pos, item.f

print isinlist((1,1))
print isinlist((1,5))

nextNode = lowestF()
print nextNode.pos, nextNode.f


The above is more efficient and simpler. It is still O(N) for the lowestF()
function. Changing data structure could make that more efficient.


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-21 Thread Dan Sommers
On Tue, 21 Jan 2014 10:32:13 +, Oscar Benjamin wrote:

> ... When you set assignments the students will usually learn more if
> they work in groups. However at some point you need to try and assess
> how much they've individually learned. I find in practice that it's
> easy to tell when a student has copied someone else without really
> understanding what they're doing though. Of course if they just pay
> someone else to do it for them then there's not much you can do...

I had a programming teacher in high school who encouraged us to work
however we wanted, individually or in groups.  There were two
conditions:  (1) each student had to turn in a complete assignment, and
(2) he reserved the right to question anyone about anything they turned
in.  He observed us working in class enough to know whom to question.  I
know that a couple of students were busted early on; I don't know how it
all turned out in the end.

Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Flushing out data from Popen buffer

2014-01-21 Thread abc79721
I am working on a python script that reads data by tailing a file and then puts 
in a different file. The script works in a time bound manner and eventually 
flushes out the data from the buffer when the ENDTIME is reached. However there 
has been a mismatch in the source and target file in terms of size.

Following is a snippet:

self.read_size = 2048
self.tail_buffer = 2048

# start the file tail
cmd = '%s -f -o %s %s' % (self.jtailcmd, offset, self.source_journal)
self.logger.debug('[%s] starting FILETail' % self.getName())
try:
self.jtail = popen2.Popen3(cmd, bufsize = self.tail_buffer)
self.jtail.tochild.close()
out = self.jtail.fromchild
outfd = self.jtail.fromchild.fileno()
flags = fcntl.fcntl(outfd, fcntl.F_GETFL)
fcntl.fcntl(outfd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
except:
message = '[%s] error reading file' % self.getName()
self.logger.error(message)
self.logger.error('[%s] %s: %s' % \
(self.getName(), sys.exc_info()[0], sys.exc_info()[1]))
send_alert('AE', message)
self.sleep(60)
self.close_tail()
self.close_ssh()
And then eventually it flushes out the data:

try:
[i, o, e] = select.select([outfd], [], [], 1)
if i:
data = out.read(self.read_size)
else:
data = None
except:
message = '[%s] error reading file' % self.getName()
self.logger.error(message)
self.logger.error('[%s] %s: %s' % \
(self.getName(), sys.exc_info()[0], sys.exc_info()[1]))
send_alert('AE', message)
self.close_tail()
self.close_ssh()
self.sleep(60)
break
if data:
if self.sshcat.poll() != -1:
self.logger.error('[%s] connection error' % self.getName())
self.close_tail()
self.close_ssh()
break
try:
self.sshcat.tochild.writelines(data)
self.sshcat.tochild.flush()
except:
message = '[%s] error writing remote file' % self.getName()
While troubleshooting, I narrowed out the problem to tail_buffer size! By 
reducing the tail_buffer size , the script worked fine. I cant use 
subprocess(Python Version is 2.4.3)

I do not want to rely on tail_buffer size. Ideally the script should be 
independent of it!

Is there a way to flush data from the POPEN buffer ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
Am Dienstag, 21. Januar 2014 14:38:34 UTC+1 schrieb Robert Voigtländer:
> > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote:
> 
> > 
> 
> 
> 
> > > I have objects like this:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > class Node(object): 
> 
> > 
> 
> > > def __init__(self, pos, parent, g , h): 
> 
> > 
> 
> > > self.pos = pos 
> 
> > 
> 
> > > self.parent = parent 
> 
> > 
> 
> > > self.g = g 
> 
> > 
> 
> > > self.h = h 
> 
> > 
> 
> > > self.f = g+h 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > I need to build a "list" of these objects. The amount is unknown.
> 
> > 
> 
> > > On this list I need to regularly
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 1. check if a specific item - identified by Node.pos - is in the list.
> 
> > 
> 
> > > 2. find the object with the lowest Node.f attribute and update or remove 
> > > it
> 
> > 
> 
> 
> 
> 
> 
> First thanks to all who responded. Although I only partially understand your 
> answers as I am a Python starter.
> 
> What's clear to me is the difference between object and instance of an 
> object. Just didn't explain it well.  
> 
> 
> 
> Maybe I give some more info on what I need / want to do. I will also provide 
> a working code example. Should have done this before.
> 
> 
> 
> I would very much appreciate a working example of what you mean. Then I have 
> a chance to understand it. :-)
> 
> 
> 
> I would like to implement a class for a A* pathfinding algorithm. (there are 
> ready libraries out there but I would like to learn it myself) This requires 
> to maintain a list of nodes to be processed and nodes already processed. For 
> new nodes I need to check if they are on one of the lists. I also need to 
> regularly pick the node with the lowest value f from the list.
> 
> 
> 
> Here some working code. For one function I sill need a solution. Any better 
> solution is welcome.
> 
> 
> 
> Thanks
> 
> Robert

Sorry - found a bug right after my post.
Here the corrected version.

class Node:
def __init__(self, pos, parent, g , h):
self.pos = pos
self.parent = parent
self.g = g
self.h = h
self.f = g+h


def isinlist(nodeToSeatch):
for item in openlist:
if item.pos == nodeToSeatch: return True
return False


def lowestF():
lowestF = ''
for item in openlist:
if item.f < lowestF:
lowestF = item.f
lowestFItem = item
return lowestFItem

def deleteItemWithPos(pos):
## need this function or different approach
pass

openlist=[]
openlist.append(Node((1,1),None,1,5))
openlist.append(Node((1,2),(1,1),4,6))
openlist.append(Node((1,3),(1,2),9,10))

for item in openlist: print item.pos, item.f

print isinlist((1,1))
print isinlist((1,5))

nextNode = lowestF()
print nextNode.pos, nextNode.f
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer

> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote:
> 

> > I have objects like this:
> 
> > 
> 
> > class Node(object): 
> 
> > def __init__(self, pos, parent, g , h): 
> 
> > self.pos = pos 
> 
> > self.parent = parent 
> 
> > self.g = g 
> 
> > self.h = h 
> 
> > self.f = g+h 
> 
> > 
> 
> > 
> 
> > I need to build a "list" of these objects. The amount is unknown.
> 
> > On this list I need to regularly
> 
> > 
> 
> > 1. check if a specific item - identified by Node.pos - is in the list.
> 
> > 2. find the object with the lowest Node.f attribute and update or remove it
> 


First thanks to all who responded. Although I only partially understand your 
answers as I am a Python starter.
What's clear to me is the difference between object and instance of an object. 
Just didn't explain it well.  

Maybe I give some more info on what I need / want to do. I will also provide a 
working code example. Should have done this before.

I would very much appreciate a working example of what you mean. Then I have a 
chance to understand it. :-)

I would like to implement a class for a A* pathfinding algorithm. (there are 
ready libraries out there but I would like to learn it myself) This requires to 
maintain a list of nodes to be processed and nodes already processed. For new 
nodes I need to check if they are on one of the lists. I also need to regularly 
pick the node with the lowest value f from the list.

Here some working code. For one function I sill need a solution. Any better 
solution is welcome.

Thanks
Robert

---
class Node:
def __init__(self, pos, parent, g , h):
self.pos = pos
self.parent = parent
self.g = g
self.h = h
self.f = g+h


def isinlist(nodeToSeatch):
for item in openlist:
if item.pos == nodeToSeatch: return True
return False


def lowestF():
lowestF = ''
for item in openlist:
if item.f < lowestF: lowestF = item
return lowestF

def deleteItemWithPos(pos):
## need this function or different approach
pass

openlist=[]
openlist.append(Node((1,1),None,1,5))
openlist.append(Node((1,2),(1,1),4,6))
openlist.append(Node((1,3),(1,2),9,10))

for item in openlist: print item.pos, item.f

print isinlist((1,1))
print isinlist((1,5))

nextNode = lowestF()
print nextNode.pos, nextNode.f
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Early retirement project?

2014-01-21 Thread Larry Martell
On Tue, Jan 21, 2014 at 1:30 AM, Devin Jeanpierre
 wrote:
> Congrats on the early retirement! It takes guts to decide to do that. :)

I thought it took money.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:use class in class

2014-01-21 Thread Dave Angel
 Robert Voigtländer  Wrote in message:
> Hi,
> 
> I have a problem using a class object within another class.
> It is about the line:
> 
> self.openlist.append(Node(self.start, None, 0, 0))
> 
> If I use it in __init__ it works. If I use it in calcRoute(self) I get the 
> following error:  local variable 'node' referenced before assignment The 
> error occures in AMap.calcRoute()
> 
> Where is my mistake?

Chris has addressed your coding error.  Within a function/method, 
 you really should use a name for just one purpose,  and
 especially if one of the purposes is global.

But you have a different problem as well. You're describing an
 exception by retyping one of its lines, rather than using
 copy/paste of the whole thing. The actual error message could not
 have said "node", as there's no such name in the method.
 
> 
> 
> 
> 
> def calcRoute(self):
> self.openlist.append(Node(self.start, None, 0, 0))
> for Node in self.openlist: print Node.pos, Node.parent, Node.g, 
> Node.h, Node.f
> 

-- 
DaveA

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Oscar Benjamin
On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtländer wrote:
> Hi,
> 
> which would be the best data structure to use for the following case?
> 
> I have objects like this:
> 
> class Node(object): 
> def __init__(self, pos, parent, g , h): 
> self.pos = pos 
> self.parent = parent 
> self.g = g 
> self.h = h 
> self.f = g+h 
> 
> 
> I need to build a "list" of these objects. The amount is unknown.
> On this list I need to regularly
> 
> 1. check if a specific item - identified by Node.pos - is in the list.
> 2. find the object with the lowest Node.f attribute and update or remove it
> 
> 
> What would be a good approach. Using a list I always need to traverse the 
> whole list to do one of the above actions.

Is the order of the items in the list significant?

If not you might try using a modification of this sorted dict recipe:
http://code.activestate.com/recipes/576998-sorted-dictionary/

You would want to use node.pos as the key and node as the value but modify the
_sorted_list so that it sorts keys according to Node.f.

Strictly speaking the sorted dict above has an O(N) overhead for insertion and
removal and O(NlogN) for creation. However these particular big-O's are
handled quite efficiently by the sort(), list.insert() and list.remove()
functions so it depends how big the list is.

If that's not okay then you may want the sorteddict from the blist package on
PyPI:
http://stutzbachenterprises.com/blist/sorteddict.html

That would give you O(logN) insertion/removal. The problem is that the sort
key() function only gets to operate on the dict key not the value so you'd
have to do something pretty funky to make it work. Perhaps:

from blist import sorteddict

def my_sorteddict(*args, **kwargs):
# There's a good chance this doesn't work...
def keyfunc(dictkey):
return d[dictkey].f
d = sorteddict(keyfunc, *args, **kwargs)
return d


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Early retirement project?

2014-01-21 Thread Tim Chase
On 2014-01-21 00:00, xeysx...@gmail.com wrote:
> Well, I retired early, and I guess now I've got some spare time to
> learn about programming, which always seemed rather mysterious. I
> am using an old mac as my main computer, and it runs os x 10.4 is
> this too old? It fills my needs, and I am on a fixed income and
> can't really afford to buy another. I think python would be a good
> starter language, based on what I've read on the net.

It's certainly a great way to consume lots of hours :)

Mac OS X 10.4 should come with an older version of Python
out-of-the-box.  The install media should also include XCode if you
want to download the latest & greatest version of Python and install
that from source instead.

-tkc


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Ben Finney
Robert Voigtländer  writes:

> which would be the best data structure to use for the following case?

First up, I want to compliment you on asking exactly the right question.
Getting the data structure right or wrong can often shape the solution
dramatically.

> I have objects like this:
>
> class Node(object): 
> def __init__(self, pos, parent, g , h): 
> self.pos = pos 
> self.parent = parent 
> self.g = g 
> self.h = h 
> self.f = g+h 

It's important to note a distinction: The class ‘Node’ doesn't have
attributes ‘pos’, ‘f’, ‘g’, ‘h’, etc. Those attributes are assigned to
each instance when the instance is initialised.

> I need to build a "list" of these objects. The amount is unknown.

Any built-in Python collection type seems good so far.

> On this list I need to regularly
>
> 1. check if a specific item - identified by Node.pos - is in the list.
> 2. find the object with the lowest Node.f attribute and update or
> remove it

So, in neither of those cases is it correct to talk of ‘Node.pos’ or
‘Node.f’, since those are attributes of the class, and the attribute
names don't exist (unless there is other code which you're not showing
us). They'll be attributes of a specific instance of the class in each
case.

> What would be a good approach. Using a list I always need to traverse
> the whole list to do one of the above actions.

If the ‘pos’ attribute is unique for all Node instances – as implied by
your “indentified by” clause above – then you could maintain a mapping
from ‘pos’ values to the Node instances:

nodes = dict()

root_node = Node(pos='root', parent=None, g=object(), h=object())
nodes[root_node.pos] = root_node

foo_node = Node(pos='foo', parent=root_node, g=object(), h=object())
nodes[foo_node.pos] = foo_node

As for finding the node with the lowest value of an attribute, I'd
recommend you just use brute force until you get concrete measurements
showing that that specific operation is occupying too much time. Write
the code correct and readable first, before trying to optimise what you
don't need to yet.

-- 
 \   “Value your freedom or you will lose it, teaches history. |
  `\ “Don't bother us with politics,” respond those who don't want |
_o__)   to learn.” —Richard Stallman, 2002 |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Early retirement project?

2014-01-21 Thread Gregory Ewing

Devin Jeanpierre wrote:


Python can run on a mac 10.4. In the worst case you may have to
download xcode and build Python from source,


There's even a Python that already comes with the system,
although it's an oldish version (somewhere around 2.5,
I think).

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: which data structure to use?

2014-01-21 Thread Chris Angelico
On Tue, Jan 21, 2014 at 10:17 PM, Robert Voigtländer
 wrote:
> 1. check if a specific item - identified by Node.pos - is in the list.
> 2. find the object with the lowest Node.f attribute and update or remove it

Are both those values constant once the Node is added? If so, the
easiest way would be to maintain a dictionary mapping pos to the Node
(or to a list of Nodes, if you can have multiple with the same pos),
and probably heapq for the f values. But if they change, you'll have
to update both data structures. If they change often, it's probably
not worth maintaining index structures - just search for what you
want, when you want it. And if you're working with a small list (say,
less than a thousand items), performance isn't going to matter at all,
so just do whatever looks cleanest in your code - probably you have
that already.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Early retirement project?

2014-01-21 Thread Gregory Ewing

xeysx...@gmail.com wrote:

I am using an old mac as my
main computer, and it runs os x 10.4 is this too old?


Not at all! It's plenty powerful enough to run Python
for educational purposes, and for some quite serious
purposes as well.

Also, Python is an excellent choice for learning
programming. There's hardly any extraneous crud to
learn before you can get started -- you just get
right down to business.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


which data structure to use?

2014-01-21 Thread Robert Voigtländer
Hi,

which would be the best data structure to use for the following case?

I have objects like this:

class Node(object): 
def __init__(self, pos, parent, g , h): 
self.pos = pos 
self.parent = parent 
self.g = g 
self.h = h 
self.f = g+h 


I need to build a "list" of these objects. The amount is unknown.
On this list I need to regularly

1. check if a specific item - identified by Node.pos - is in the list.
2. find the object with the lowest Node.f attribute and update or remove it


What would be a good approach. Using a list I always need to traverse the whole 
list to do one of the above actions.

Thanks
Robert
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use class in class

2014-01-21 Thread Robert Voigtländer
> I recommend using a different name for the instances here, probably
> 
> with a lower-case first letter. That would solve your problem _and_
> 
> make your code more readable.

Thanks a lot! I was confused by the debuger gifing me the wrong line as 
containing the error. I changed it regarding your advide. And it works.

Robert


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Imports in Python

2014-01-21 Thread Ben Finney
Johannes Schneider  writes:

> I remember some document explaining the python imports in detail
> somewhere, but I don't have any idea where it was. Even no idea if it
> was in the List or some blogbost.

What kind of detail do you want?

> Does anybody of you have some suggestions where I can find those
> informations besides the official documentation?

We'd need to know what information you want beyond what's in the
official documentation
.

-- 
 \   “I have one rule to live by: Don't make it worse.” —Hazel |
  `\  Woodcock |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use class in class

2014-01-21 Thread Chris Angelico
On Tue, Jan 21, 2014 at 9:20 PM, Robert Voigtländer
 wrote:
> def calcRoute(self):
> self.openlist.append(Node(self.start, None, 0, 0))
> for Node in self.openlist: print Node.pos, Node.parent, Node.g, 
> Node.h, Node.f

You're using the name Node to mean two different things. In the first
line, you expect it to be the global name (which is the class), but on
the second, you want to iterate over the node instances. That assigns
to the name Node, which causes your problems.

I recommend using a different name for the instances here, probably
with a lower-case first letter. That would solve your problem _and_
make your code more readable.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-21 Thread Oscar Benjamin
On Tue, Jan 21, 2014 at 12:47:41AM +, Steven D'Aprano wrote:
> On Mon, 20 Jan 2014 09:08:28 -0500, Roy Smith wrote:
> 
> > In article ,
> >  Chris Angelico  wrote:
> > 
> >> On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg 
> >> wrote:
> >> > I did a short time of teaching while I was in school.  If three
> >> > students all turned in the same assignment, they all got docked
> >> > significantly.  There was no "who copied off of whom?", it was
> >> > "someone shared when they shouldn't have."
> >> 
> >> What a wonderful way to promote an attitude of "my code is MY CODE and
> >> should never leave my sight". What a delightful way of thinking to
> >> unleash on the world.
> > 
> > That's a little harsh.  Working in groups, and sharing code, are
> > important parts of how software gets developed today.  Those
> > collaborative work habits should indeed be taught.  But, school is also
> > about evaluation of progress.  At the end of the class, the teacher
> > needs some objective way to figure out how much each student has learned
> > and assign a grade.  It's hard to do that if people aren't handing in
> > assignments done individually.

I agree that it is unfortunate but there's a bit of a balancing act with this.
The problem is that there are two sometimes conflicting roles in education:
teaching and assessing. When you set assignments the students will usually
learn more if they work in groups. However at some point you need to try and
assess how much they've individually learned. I find in practice that it's
easy to tell when a student has copied someone else without really
understanding what they're doing though. Of course if they just pay someone
else to do it for them then there's not much you can do...

> 
> An objective way to figure out individual progress is easy. It's called 
> an "exam" or "test". Admittedly, it's normally only practical for 
> examinations to last no more than a day for senior students, and an hour 
> or maximum two hours for junior students, and some subjects are more 
> easily tested this way than others. But you can still examine a lot in a 
> couple of hours. If you're interested in accurately measuring the 
> learning of individual students, there is at least one pretty damning 
> problem with assignments: just because student X puts his name on the 
> paper doesn't mean student X wrote the paper. Assignments are effectively 
> based on the honour system, and we know how well that works. For those 
> with the money to spend, you need not do a lick of work to get an A.

The real problem with exams is that exam conditions are so unrepresentative of
real work. How often do you use the internet, or documentation, or text books
etc. in your own work? How often would you have to do something without having
anyone at least to discuss the idea with?

But yes it's absolutely necessary to have some exams or else the whole system
is open to abuse.

> 
> Perhaps that's why Harvard has just given up even trying to distinguish 
> the students who learn things from those who don't? Forget George Bush's 
> "Gentleman's C", Harvard now practically gives A's away to anyone who 
> shows up (and pays the fees).

I think that's a little harsh. To say that the majority of students get an
A- or better does not mean that they give A's to "anyone who shows up". I
would expect that the majority of students at Harvard do a lot more than just
show up. (I don't know much about Harvard specifically but this is true of
most universities).

> 
> http://qz.com/153694/the-most-commonly-awarded-grade-at-harvard-is-an-a/
> 
> Presumably they're protecting their business model. Students are 
> customers, and if your customers are paying a small fortune to attend, 
> they need to get something in return. Knowledge is good, but you can't 
> put knowledge on a CV or frame it and put it on a wall.
> 
> It would be interesting to think about the incentives which have lead to 
> an over-reliance on take-home assignments rather than exams, as well as 
> the pros and cons of one versus the other. Don't get me wrong, there are 
> advantages to assignments as well, but I think that the total prohibition 
> on collaboration is misguided. The question in my mind is how to 
> encourage students to learn from each other rather than to merely 
> mechanically copy from each other?
> 
> Relevant:
> 
> http://qz.com/157579/confession-of-an-ivy-league-teaching-assistant-heres-why-i-inflated-grades/

I can definitely empathise with what she says. Once I started marking
assignments it quickly became apparent that my standards were higher than
those of other people. Every now and again I would mark a big assignment
and get a deluge of grief from the students who had done badly. If it's a
small assignment (say 5 students) then you can build something out of that and
spend time preparing them for future assignments. If it's a big assignment
(100+ students) then it's just a whole load of grief that no one really wants.

The problem 

use class in class

2014-01-21 Thread Robert Voigtländer
Hi,

I have a problem using a class object within another class.
It is about the line:

self.openlist.append(Node(self.start, None, 0, 0))

If I use it in __init__ it works. If I use it in calcRoute(self) I get the 
following error:  local variable 'node' referenced before assignment The error 
occures in AMap.calcRoute()

Where is my mistake?


Thanks
Robert

import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm

class Node(object):
def __init__(self, pos, parent, g , h):
self.pos = pos
self.parent = parent
self.g = g
self.h = h
self.f = g+h

class NewAMap(object):
def __init__(self, size, start, target):
self.size = size
self.start = start
self.target = target
self.openlist = []
self.closedlist = set()
self.EmptyValue = 0

self.clear()
self.addStart(self.start)
self.addTarget(self.target)

#self.openlist.append(Node(self.start, None, 0, 0))

def clear(self):
self.OccMap = np.zeros(shape=(self.size[0],self.size[1]),dtype=int)
def display(self):
print np.swapaxes(self.OccMap,0,1)

self.PicMap = 
np.zeros(shape=(self.size[0],self.size[1]),dtype=(float,3))
for x in xrange(0,self.size[0]):
for y in xrange(0,self.size[1]):
if self.OccMap[x][y] == 0:
self.PicMap[y][x]=(1,1,1)
elif self.OccMap[x][y] == -1:
self.PicMap[y][x]=(0,0,0)
elif self.OccMap[x][y] == -2:
self.PicMap[y][x]=(1,0,0)
elif self.OccMap[x][y] == -3:
self.PicMap[y][x]=(0,0,1)
#print self.PicMap
plt.imshow(self.PicMap, interpolation='nearest')
plt.show()

def addBlocked(self, blockposs):
self.OccMap[blockposs[0]][blockposs[1]]=-1
def addStart(self, start):
self.OccMap[start[0]][start[1]]=-2
def addTarget(self, target):
self.OccMap[target[0]][target[1]]=-3
def calcRoute(self):
self.openlist.append(Node(self.start, None, 0, 0))
for Node in self.openlist: print Node.pos, Node.parent, Node.g, Node.h, 
Node.f


def main():
AMap = NewAMap((20,20),(1,12),(12,12))
for y in range(8,17): AMap.addBlocked((8,y))
AMap.calcRoute()
AMap.display()

if __name__ == '__main__':
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Scalability TCP Server + Background Game

2014-01-21 Thread Philip Werner
> Looking a lot more normal and readable now. Thanks!
> 
> Note that some people have experienced odd issues with Pan, possibly
> relating to having multiple instances running simultaneously. You may
> want to take care not to let it open up a duplicate copy of itself.
> 
> ChrisA

Thanks for the heads up.

It is buggy to say the least. Any other program on linux you may suggest?

Regards,
Philip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Early retirement project?

2014-01-21 Thread Devin Jeanpierre
Congrats on the early retirement! It takes guts to decide to do that. :)

Python can run on a mac 10.4. In the worst case you may have to
download xcode and build Python from source, if there are no powerpc
binaries available. That's pretty simple, though (./configure && make
&& make install).

-- Devin

On Tue, Jan 21, 2014 at 12:00 AM,   wrote:
> Well, I retired early, and I guess now I've got some spare time to learn 
> about programming, which always seemed rather mysterious. I am using an old 
> mac as my main computer, and it runs os x 10.4 is this too old? It fills my 
> needs, and I am on a fixed income and can't really afford to buy another. I 
> think python would be a good starter language, based on what I've read on the 
> net.
>
> xeysxeys
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: matlabFunction Equivalent?

2014-01-21 Thread Johannes Schneider

On 20.01.2014 23:09, rpi.bal...@gmail.com wrote:

Hey all,

I'm new at Python, so if you see any mistakes feel free to let me know.

I'm trying to take a symbolic expression and turn it into a variable equation 
or function. I think that just an expression of variables would be preferable.

I have a range equation which I form using symbols and then take various 
derivatives of it. I then want to have these derivatives on hand to use for 
various functions, but short of using sub every time or just copy pasting from 
the console output (I don't want to do that), I can't find an efficient way to 
do this. Matlab had matlabFunction which was really handy, but I don't think 
Python has an equivalent.


import numpy as np
import scipy as sp
import sympy as sy
import math as ma

x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y 
z x_s y_s z_s theta theta_dot x_dot y_dot z_dot')

rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + 
y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5)

rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) 
+ theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - 
y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - 
z_dot*z_s)/rho

drho_dx = sy.diff(rho, x)

drho_dy = sy.diff(rho, y)

drho_dz = sy.diff(rho, z)

#I then want drho_dx, etc to be variable expressions with x, y, z, etc as 
variables instead of symbols or numbers. I could do:

x, y, z = 1200, 1300, 1400 #m

drho_dx = subs([x, x], [y, y], [z, z])

#but this seems inefficient to do multiple times. Thoughts?



If you  don not mind installing other programs, maybe you can have a 
look at sage (www.sagemath.org). That's a ComputerAlgebraSystem using 
python as its base and supporting most (all?) of the python syntax and 
moduls


bg,
Johannes



--
Johannes Schneider
Webentwicklung
johannes.schnei...@galileo-press.de
Tel.: +49.228.42150.xxx

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn
--
https://mail.python.org/mailman/listinfo/python-list


Imports in Python

2014-01-21 Thread Johannes Schneider

Hi List,
I remember some document explaining the python imports in detail 
somewhere, but I don't have any idea where it was. Even no idea if it 
was in the List or some blogbost.


Does anybody of you have some suggestions where I can find those 
informations besides the official documentation?


bg,
Johannes

--
Johannes Schneider
Webentwicklung
johannes.schnei...@galileo-press.de
Tel.: +49.228.42150.xxx

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn
--
https://mail.python.org/mailman/listinfo/python-list


Early retirement project?

2014-01-21 Thread xeysxeys
Well, I retired early, and I guess now I've got some spare time to learn about 
programming, which always seemed rather mysterious. I am using an old mac as my 
main computer, and it runs os x 10.4 is this too old? It fills my needs, and I 
am on a fixed income and can't really afford to buy another. I think python 
would be a good starter language, based on what I've read on the net.

xeysxeys
-- 
https://mail.python.org/mailman/listinfo/python-list