Re: Module missing when embedding?

2013-12-11 Thread Garthy
Hi all, The output I collected skipped the error messages for some reason. Updated test output with full errors follows. Cheers, Garth --- rm -f applepy applepy.o gcc -c -o applepy.o applepy.c -g -Wall -I/opt/python/include/python3.3m gcc -o applepy applepy.o -g -Wall -L/opt/python/lib -lpy

Comparing values of counter in python 3.3

2013-12-11 Thread Amjad Syed
Hello, I have 2 counters generated from list using Collections.counter() I want to print only key,values in Counter2 which have values > then corresponding value in Counter1. E.g Counter1={97:1,99:2,196:2,198:1} Counter2={97:1 ,99:3, 196:1,198:1} # Output [99,3] # Need to compare values of co

Re: Module missing when embedding?

2013-12-11 Thread Garthy
Hi all, I've written a minimal set of tests illustrate the issue, which also confirms it is independent of threading. Details below. If you build it, you might need to tweak the Makefile to run on your system. The script "run" will run all eight tests. They pass only when we load everything

Module missing when embedding?

2013-12-11 Thread Garthy
Hi all, I am attempting to embed Python 3.3.3 into an application. Following advice which suggests not using multiple interpreters, I am experimenting using a *single* interpreter and multiple threads. So far I have been loading directly into "__main__", ie. something like this: PyObject

min max from tuples in list

2013-12-11 Thread Robert Voigtländer
Hi, I have a list like this: a = [(52, 193), (52, 193), (52, 192), (51, 193), (51, 191), (51, 190), (51, 189), (51, 188), (50, 194), (50, 187), (50, 186), (50, 185), (50, 184), (49, 194), (49, 183), (49, 182), (49, 181), (48, 194), (48, 180), (48, 179), (48, 178), (48, 177), (47, 194), (47, 17

Re: load_module for import entire package

2013-12-11 Thread alex23
On 11/12/2013 5:28 PM, Sergey wrote: def get_obj(): pkg = load_package_strict("tmp", basedir) from tmp import main return main.TTT() It is working, but if package code changes on disc at runtime and I call get_obj again, it returns instance of class, loaded for the first time previous

Re: Figuring out what dependencies are needed

2013-12-11 Thread sal i
On Thursday, December 12, 2013 1:48:42 PM UTC+8, alex23 wrote: > On 11/12/2013 10:44 PM, s...@nearlocal.com wrote: > > > I'm a Python beginner. I want to use it for stats work, so I downloaded > > Anaconda which has several of the popular libraries already packaged for > > Mac OS X. > > > > >

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Michael Torrie
On 12/11/2013 04:39 PM, Dan Stromberg wrote: >> If you can, would you please turn off rich text posting when you post >> here please? > Apologies. I didn't realize gmail was doing this. I had thought it would > only do so if I used the formatting options in the composer, but perhaps it > does s

Re: Strange crashes

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 4:47 PM, Igor Korot wrote: > So, when I find the culprit variable what do I do? > Make it a part of some class? Protect it with mutex? > > How to solve this? And most importantly, how do _I_ verify that its solved? >From the look of the error, protecting it with a mutex wo

Re: Strange crashes

2013-12-11 Thread Roy Smith
In article , Chris Angelico wrote: > On Thu, Dec 12, 2013 at 4:25 PM, Igor Korot wrote: > > ProgrammingError: SQLite objects created in a thread can only be used > > in that same thread.The object was created in thread id 14260 and this > > is thread id 9264 > > > > Where should I start looking

Re: Strange crashes

2013-12-11 Thread Igor Korot
Hi, Chris, On Wed, Dec 11, 2013 at 9:31 PM, Chris Angelico wrote: > On Thu, Dec 12, 2013 at 4:25 PM, Igor Korot wrote: >> ProgrammingError: SQLite objects created in a thread can only be used >> in that same thread.The object was created in thread id 14260 and this >> is thread id 9264 >> >> Whe

Re: Figuring out what dependencies are needed

2013-12-11 Thread alex23
On 11/12/2013 10:44 PM, s...@nearlocal.com wrote: I'm a Python beginner. I want to use it for stats work, so I downloaded Anaconda which has several of the popular libraries already packaged for Mac OS X. Now I'd like to use the backtesting package from zipline (zipline.io), but while runnin

Re: Trouble with Multi-threading

2013-12-11 Thread David Hutto
If you really want to have a discussion on multi-threading, then look at quantum bits/computers, and let's see where python can go from the real future of prototyping language, to the expert in it. On Wed, Dec 11, 2013 at 11:26 PM, rusi wrote: > On Thursday, December 12, 2013 7:30:38 AM UTC+5:

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread alex23
On 11/12/2013 8:45 PM, Chris Angelico wrote: A round of applause for jmf, folks, for doing a brilliant impression of the uninformed-yet-fanatical Knight Templar villain! Jacques de Molay, thou are avenged! -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange crashes

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 4:25 PM, Igor Korot wrote: > ProgrammingError: SQLite objects created in a thread can only be used > in that same thread.The object was created in thread id 14260 and this > is thread id 9264 > > Where should I start looking for causes? Well, I'd look for something that cr

Strange crashes

2013-12-11 Thread Igor Korot
Hi, ALL, I'm trying to develop a software with Python. It uses multi threading. For some unknown reason the program crashes on my employer's machine but on mine it runs fine. Exception in thread Thread-3: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 552, in __boo

Re: Trouble with Multi-threading

2013-12-11 Thread rusi
On Thursday, December 12, 2013 7:30:38 AM UTC+5:30, Roy Smith wrote: > In article Steven D'Aprano wrote: > > When did this forum become so intolerant of even the tiniest, most minor > > breaches of old-school tech etiquette? Have we really got nothing better > > to do than to go on the war path

Re: Disable HTML in forum messages (was: Movie (MPAA) ratings and Python?)

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 2:23 PM, rusi wrote: > When you click on send/reply in gmail, there's a small down-triangle > next to the dustbin, inside which you will find a plain text option > > The problem is that then your other mails (may) become plain text and > your friends/recipients will wonder

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 2:52 PM, rusi wrote: > Which comes back full-circle to where we started: if > > main() { printf("Hello World\n"); } > > is the foundation on which other programs are built, then later excising > the print(f) is a significant headache -- at least for teachers as Steven > als

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread rusi
On Thursday, December 12, 2013 7:12:32 AM UTC+5:30, Roy Smith wrote: > rusi wrote: > > Kernighan and Ritchie set an important "first" in our field by making > > "Hello World" their first program. > Yup. > > People tend to under-estimate the importance of this: > > Many assumptions need to be v

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 5:01 PM, Ned Batchelder wrote: > On 12/11/13 6:39 PM, Dan Stromberg wrote: > >> >> On Wed, Dec 11, 2013 at 3:24 PM, Steven D'Aprano >> > > wrote: >> >> On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: >> >> > $

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Dan Stromberg
On Tue, Dec 10, 2013 at 4:02 PM, Tamer Higazi wrote: > Hi people! > > Is there a way to get dict by search terms without iterating the entire > dictionary ?! > > Let us assume I have: > > {'Amanda':'Power','Amaly':'Higgens','Joseph':'White',' > Arlington','Black','Arnold','Schwarzenegger'} > > I

Re: Disable HTML in forum messages (was: Movie (MPAA) ratings and Python?)

2013-12-11 Thread rusi
On Thursday, December 12, 2013 6:42:42 AM UTC+5:30, Ben Finney wrote: > Dan Stromberg writes: > > I found a "remove formatting" button in gmail's composer, and used it > > on this message. Does this message look like plain text? > Still sent with an HTML part, so some other change must be needed

Re: The increasing disempowerment of the computer user

2013-12-11 Thread Mark Lawrence
On 12/12/2013 02:21, Ben Finney wrote: Only, now we get worldwide unaccountable surveillance as part of the deal. Whereas the 1920 UK Official Secrets Act required all international cable companies operating on British terrority to submit copies of all their traffic (both dispatched and rec

Re: The increasing disempowerment of the computer user

2013-12-11 Thread Ben Finney
Ben Finney writes: > Larry Martell writes: > > > On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > > > rusi wrote: > > > > > >> Many assumptions need to be verified/truthified/dovetailed > > >> starting from switching on the machine onwards for this to work. > > > > > > At the time that [Ker

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Roy Smith
In article , Larry Martell wrote: > On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > > In article , > > rusi wrote: > > > >> Kernighan and Ritchie set an important "first" in our field by making > >> "Hello World" their first program. > > > > Yup. > > > >> People tend to under-estimate the

Re: Optimizing list processing

2013-12-11 Thread Terry Reedy
On 12/11/2013 6:54 PM, Steven D'Aprano wrote: I have some code which produces a list from an iterable using at least one temporary list, using a Decorate-Sort-Undecorate idiom. It is a non-standard version thereof, as DSU usually means to decorate with a key that gets discarded. A couple of

The increasing disempowerment of the computer user (was: Experiences/guidance on teaching Python as a first programming language)

2013-12-11 Thread Ben Finney
Larry Martell writes: > On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > > rusi wrote: > > > >> Many assumptions need to be verified/truthified/dovetailed > >> starting from switching on the machine onwards for this to work. > > > > At the time that [Kerningham & Ritchie] wrote [the C progra

Re: Optimizing list processing

2013-12-11 Thread MRAB
On 12/12/2013 01:43, Steven D'Aprano wrote: On Thu, 12 Dec 2013 00:59:42 +, MRAB wrote: table = [(x, i) for i,x in enumerate(iterable)] table.sort() This looks wrong to me: for x, i in table: table[i] = x Yes, you're right, I over-simplified the example, and in doing so introduce

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Larry Martell
On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > In article , > rusi wrote: > >> Kernighan and Ritchie set an important "first" in our field by making >> "Hello World" their first program. > > Yup. > >> People tend to under-estimate the importance of this: >> Many assumptions need to be verif

Re: Trouble with Multi-threading

2013-12-11 Thread Roy Smith
In article <52a84061$0$29992$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > When did this forum become so intolerant of even the tiniest, most minor > breaches of old-school tech etiquette? Have we really got nothing better > to do than to go on the war path over such trivial is

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Roy Smith
In article , Mark Lawrence wrote: > On 11/12/2013 16:04, Chris Angelico wrote: > > I strongly believe that a career > > programmer should learn as many languages and styles as possible, but > > most of them can wait. > > I chuckle every time I read this one. Five years per language, ten > lan

Re: Optimizing list processing

2013-12-11 Thread Steven D'Aprano
On Thu, 12 Dec 2013 00:59:42 +, MRAB wrote: >> table = [(x, i) for i,x in enumerate(iterable)] >> table.sort() > > This looks wrong to me: > >> for x, i in table: >> table[i] = x Yes, you're right, I over-simplified the example, and in doing so introduced a bug. What I actually use i

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Roy Smith
In article , rusi wrote: > Kernighan and Ritchie set an important "first" in our field by making > "Hello World" their first program. Yup. > People tend to under-estimate the importance of this: > Many assumptions need to be verified/truthified/dovetailed > starting from switching on the machi

New class to visualize binary search trees

2013-12-11 Thread lecturemaker . tv
I just completed the MITx course: Introduction to Computer Science using Python: 6.00.1x located on the edX website: edx.org. I thought I would share a class I crafted in python to display and animate binary search trees. It's my first course in python. Code, videos, and discussion available

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread M.F.
On 12/12/2013 03:10 AM, brian cleere wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. #!/bin/env python import csv import sys if len(sys.argv) < 3: print('Please specify a filename and column number: {} [csvfile] [c

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 6:01 PM, Ned Batchelder wrote: >> I've also been wondering if ISO-8859-1 is just an octet-oriented codec, >> so it'll read about anything. There are clearly non-7-bit-ASCII >> characters in the file that look like line noise in an mrxvt. > > > Both ISO-8859-1 and Windows-1

Re: Disable HTML in forum messages (was: Movie (MPAA) ratings and Python?)

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 6:12 PM, Ben Finney wrote: >> I found a "remove formatting" button in gmail's composer, and used it >> on this message. Does this message look like plain text? > > Still sent with an HTML part, so some other change must be needed to > disable that. Check the default format

Re: Optimizing list processing

2013-12-11 Thread Ben Finney
Steven D'Aprano writes: > For giant iterables (ten million items), this version is a big > improvement, about three times faster than the list comp version. […] > > Except that for more reasonably sized iterables, it's a pessimization. > With one million items, the ratio is the other way around:

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 6:02 PM, Ian Kelly wrote: > This is what I did not so long ago when writing a utility for > typeahead lookup, except that to save some space and time I only > nested the dicts as deeply as there were still multiple entries. As > an example of what the data structure looked

Disable HTML in forum messages (was: Movie (MPAA) ratings and Python?)

2013-12-11 Thread Ben Finney
Dan Stromberg writes: > On Wed, Dec 11, 2013 at 3:24 PM, Steven D'Aprano < > steve+comp.lang.pyt...@pearwood.info> wrote: > > By the way, this forum is a text-only newsgroup and so-called "Rich > > Text" (actually HTML) posts are frowned upon […] > > If you can, would you please turn off rich tex

Re: Optimizing list processing

2013-12-11 Thread duncan smith
On 11/12/13 23:54, Steven D'Aprano wrote: I have some code which produces a list from an iterable using at least one temporary list, using a Decorate-Sort-Undecorate idiom. The algorithm looks something like this (simplified): table = sorted([(x, i) for i,x in enumerate(iterable)]) table = [i fo

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 7:30 AM, Tim Chase wrote: > On 2013-12-11 13:44, Steven D'Aprano wrote: >> If necessary, I would consider having 26 dicts, one for each >> initial letter: >> >> data = {} >> for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": >> data[c] = {} >> >> then store keys in the particular d

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Ned Batchelder
On 12/11/13 6:39 PM, Dan Stromberg wrote: On Wed, Dec 11, 2013 at 3:24 PM, Steven D'Aprano mailto:steve+comp.lang.pyt...@pearwood.info>> wrote: On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: > $ chardet mpaa-ratings-reasons.list > mpaa-ratings-reasons.list: windows-125

Re: Optimizing list processing

2013-12-11 Thread MRAB
On 11/12/2013 23:54, Steven D'Aprano wrote: I have some code which produces a list from an iterable using at least one temporary list, using a Decorate-Sort-Undecorate idiom. The algorithm looks something like this (simplified): table = sorted([(x, i) for i,x in enumerate(iterable)]) table = [i

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Christopher Welborn
On 12/11/2013 01:41 PM, Mark Lawrence wrote: On 11/12/2013 19:22, Chris Angelico wrote: There is, https://pypi.python.org/pypi/docopt/0.6.1 :) +1 for docopt. It makes everything very clear. Just type out your usage string, and then run docopt(usage_str) on it to get a dict of your args. When

Optimizing list processing

2013-12-11 Thread Steven D'Aprano
I have some code which produces a list from an iterable using at least one temporary list, using a Decorate-Sort-Undecorate idiom. The algorithm looks something like this (simplified): table = sorted([(x, i) for i,x in enumerate(iterable)]) table = [i for x,i in table] The problem here is that

Re: [newbie] trying socket as a replacement for nc

2013-12-11 Thread Conor Hughes
Jean Dubois writes: > I have an ethernet-rs232 adapter which allows me to connect to a > measurement instrument by means of netcat on a linux system. > e.g. entering nc 10.128.59.63 7000 > allows me to enter e.g. > *IDN? > after which I get an identification string of the measurement > instrument

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 3:24 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: > > > $ chardet mpaa-ratings-reasons.list > > mpaa-ratings-reasons.list: windows-1255 (confidence: 0.97) > > > > I'm aware that chardet is pla

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: > $ chardet mpaa-ratings-reasons.list > mpaa-ratings-reasons.list: windows-1255 (confidence: 0.97) > > I'm aware that chardet is playing guessing games, though one would hope > it would guess well most of the time, and give a reasonable co

Re: [newbie] trying socket as a replacement for nc

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois wrote: > I have an ethernet-rs232 adapter which allows me to connect to a > measurement instrument by means of netcat on a linux system. > e.g. entering nc 10.128.59.63 7000 > allows me to enter e.g. > *IDN? > after which I get an identification string

Re: Tracking the status of python script execution

2013-12-11 Thread Dan Stromberg
Long ago, I saw a C program that took another C program as input. It would output a copy of the original C program, interspersed with fprintf's that would display the text of the line current being executed. You might write something similar for Python, perhaps outputting the line being executed

[newbie] trying socket as a replacement for nc

2013-12-11 Thread Jean Dubois
I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an identification string of the measurement instrument back. I thought I could accomplish

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 10:35 AM, Ned Batchelder wrote: > On 12/10/13 6:50 PM, Dan Stromberg wrote: > Now the question becomes: Why did chardet tell me it was windows-1255? :) > > It probably told you it was Windows-1252 (I'm assuming the last 5 is a > typo). > > Windows-1252 is a super-set of IS

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Ethan Furman
On 12/11/2013 12:34 AM, Devin Jeanpierre wrote: On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman wrote: Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially if your degree is not in CS. One of the (many) nic

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Terry Reedy
On 12/11/2013 5:26 AM, Ben Finney wrote: Better design is to make the argument list a parameter to the ‘main’ function; this allows constructing an argument list specially for calling that function, without ‘main’ needing to know the difference. You'll also want to catch SystemExit and return t

Re: Figuring out what dependencies are needed

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 6:38 AM, Robert Kern wrote: > On 2013-12-11 13:27, Steven D'Aprano wrote: >> >> On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: >> >>> Now I'd like to use the backtesting package from zipline (zipline.io), >> >> >> ".io" is not normally a file extension for Python files. Are

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 20:03, Chris Angelico wrote: On Thu, Dec 12, 2013 at 7:00 AM, Mark Lawrence wrote: I use the alternative X for a mandatory argument X. Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo to (x,y) $0 bar x y z Go

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Tim Chase
On 2013-12-12 07:03, Chris Angelico wrote: > Also common, but how do you specify a keyword, then? Say you have a > command with subcommands: > > $0 foo x y > Move the foo to (x,y) > $0 bar x y z > Go to bar X, order a Y, and Z it [eg 'compress', 'gzip', 'drink'] > > How do you show that x/y/z are

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Tim Delaney
On 12 December 2013 03:25, Chris Angelico wrote: > On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence > wrote: > > On 11/12/2013 16:04, Chris Angelico wrote: > >> > >> I strongly believe that a career > >> programmer should learn as many languages and styles as possible, but > >> most of them can wa

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 7:00 AM, Mark Lawrence wrote: > I use the alternative X for a mandatory argument X. Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo to (x,y) $0 bar x y z Go to bar X, order a Y, and Z it [eg 'compress',

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 19:46, Chris Angelico wrote: On Thu, Dec 12, 2013 at 6:41 AM, Mark Lawrence wrote: Square brackets in a usage description often mean "optional". You may want to be careful of that. There's no really good solution though. There is, https://pypi.python.org/pypi/docopt/0.6.1 :) T

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 6:41 AM, Mark Lawrence wrote: >> Square brackets in a usage description often mean "optional". You may >> want to be careful of that. There's no really good solution though. > > There is, https://pypi.python.org/pypi/docopt/0.6.1 :) That appears to use for a mandatory arg

Re: Tracking the status of python script execution

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 6:26 AM, Shyam Parimal Katti wrote: > I am looking for a library that can help me trace the status of a live > python script execution. i.e if I have a python script `x.py` with 200 > lines, when I execute the script with `python x.py`, is there a way to trace > the status

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 19:22, Chris Angelico wrote: On Thu, Dec 12, 2013 at 6:10 AM, brian cleere wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. Your problem is akin to debugging an empty file :) It's not so much a matter of f

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 19:10, brian cleere wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. #!/bin/env python import csv You never use the csv module. import sys if len(sys.argv) < 3: print('Please specify a filename and

Tracking the status of python script execution

2013-12-11 Thread Shyam Parimal Katti
Hello All, I am looking for a library that can help me trace the status of a live python script execution. i.e if I have a python script `x.py` with 200 lines, when I execute the script with `python x.py`, is there a way to trace the status of this execution in terms of number of lines executed so

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 6:10 AM, brian cleere wrote: > I know the problem is with the for loop but don't know how to fix. Any help > with explanation would be appreciated. Your problem is akin to debugging an empty file :) It's not so much a matter of fixing what's not working as of starting at

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Tim Chase
On 2013-12-11 11:10, brian cleere wrote: > filename = sys.argv[1] > column = int(sys.argv[2]) > > for line in filename() , column (): > elements = line.strip().split(',') > values.append(int(elements[col])) 1) you need to open the file 2) you need to make use of the csv module on that fi

adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread brian cleere
I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. #!/bin/env python import csv import sys if len(sys.argv) < 3: print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0])) sys.exit(1) f

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Ned Batchelder
On 12/10/13 6:50 PM, Dan Stromberg wrote: On Tue, Dec 10, 2013 at 1:07 PM, Petite Abeille mailto:petite.abei...@gmail.com>> wrote: On Dec 10, 2013, at 6:25 AM, Dan Stromberg mailto:drsali...@gmail.com>> wrote: > The IMDB flat text file probably came the closest, but it appears to

Re: Script Request

2013-12-11 Thread Johannes Findeisen
Hi, On Wed, 11 Dec 2013 04:53:41 -0700 Jeff James wrote: > Looking for a script which will check connectivity of any or all of our > company URL's first thing in the morning to make sure none or our sites are > down. Any suggestions ? Thank You This really is not a suggestion because the s

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Petite Abeille
On Dec 11, 2013, at 12:50 AM, Dan Stromberg wrote: > Now the question becomes: Why did chardet tell me it was windows-1255? :) As it says on the tin: chardet guesses the encoding of text files. The operative word is ‘guesses’. -- https://mail.python.org/mailman/listinfo/python-list

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Mark Lawrence
On 11/12/2013 17:19, Travis Griggs wrote: On Dec 11, 2013, at 5:31 AM, rusi wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ My thoughts exactly! I

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Travis Griggs
On Dec 11, 2013, at 5:31 AM, rusi wrote: > > The classic data structure for this is the trie: > General idea: http://en.wikipedia.org/wiki/Trie > In python: > http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ My thoughts exactly! If you wade through the comments ther

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 3:27 AM, rusi wrote: > However when we have an REPL language like python, one has the choice > of teaching the hello-world program as: > > print ("Hello World") > > or just > > "Hello World" > > The second needs one more assumption than the first, viz that we are in the > R

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 08:27:23 -0800, rusi wrote: > [BTW: From the theoretical POV, imperative programming is 'unclean' > because of assignment statements. From the practical POV of a teacher, > the imperativeness of print is a bigger nuisance in students' thinking > patterns ] +1 on this Trying

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 9:31:42 PM UTC+5:30, bob gailer wrote: > On 12/11/2013 3:43 AM, Chris Angelico wrote: > > When you tell a story, it's important to engage the reader from the > > start...explain "This is how to print Hello World to the > > console" and worry about what exactly the co

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence wrote: > On 11/12/2013 16:04, Chris Angelico wrote: >> >> I strongly believe that a career >> programmer should learn as many languages and styles as possible, but >> most of them can wait. > > > I chuckle every time I read this one. Five years per l

Re: python import error

2013-12-11 Thread John Gordon
In <58f7bd2a-ef82-4782-b4fb-db824f9c8...@googlegroups.com> smilesonisa...@gmail.com writes: > > > File "aaa.py", line 5, in > > > > > from ccc.ddd import sss > > > > > ImportError: No module named ccc.ddd > > > > > directory structure as follows: > > > > > ccc > > > | > > > ddd > > >

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Mark Lawrence
On 11/12/2013 16:04, Chris Angelico wrote: I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. I chuckle every time I read this one. Five years per language, ten languages, that's 50 years I think. Or do I rewrite my d

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 3:01 AM, bob gailer wrote: > One student (PhD in Physics) looked at X = X + 1 and said "no it doesn't". Yeah, which is why some languages (I first met it with Pascal) spell that as "X *becomes* X + 1"... but regardless of what you call it, there's a fundamental difference

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Mark Lawrence
On 11/12/2013 16:01, bob gailer wrote: One student (PhD in Physics) looked at X = X + 1 and said "no it doesn't". Someone I worked with used x := x - x - x to invert a number. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark La

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Mark Lawrence
On 11/12/2013 00:02, Tamer Higazi wrote: Hi people! Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'} I want to grab the dict's key and

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 2:41 AM, rusi wrote: > Yes its always like that: > When you have to figure 2 (or 10) line programs its a no-brainer that > the imperative style just works. > > When the ten becomes ten-thousand, written by a nut who's left you with > code whose semantics is dependent on wei

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread bob gailer
On 12/11/2013 3:43 AM, Chris Angelico wrote: When you tell a story, it's important to engage the reader from the start...explain "This is how to print Hello World to the console" and worry about what exactly the console is (and how redirection affects it) Highly agree. I was once given FORTRAN co

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Mark Lawrence
On 11/12/2013 15:41, rusi wrote: When the ten becomes ten-thousand, written by a nut who's left you with code whose semantics is dependent on weird dependencies and combinatorial paths through the code you start wishing that ... he'd not been a Led Zeppelin fan, whereby every variable/module

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 2:42 AM, bob gailer wrote: > It also ensures that the defining all the classes and functions happens > before referencing them (less "bookkeeping" for me). > > These two allow me to write the main program first, and follow it with all > the global stuff. I prefer define-be

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Neil Cerutti
On 2013-12-11, Dennis Lee Bieber wrote: > On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing > declaimed the following: >>> On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: 5) Learning to program "should be painful" and we should expect the students to complain about i

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 8:54:30 PM UTC+5:30, Chris Angelico wrote: > On Thu, Dec 12, 2013 at 1:44 AM, rusi wrote: > > It is this need to balance that makes functional programming attractive: > > - implemented like any other programming language > > - but also mathematically rigorous > Attr

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread bob gailer
On 12/11/2013 4:55 AM, JL wrote: What is the advantage to using a main()? In addition to what's been said I add: It separates all the global activities: defining of functions and classes, importing modules, etc. from the "doing" the actual task of the program. It also ensures that the defin

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 09:46, Roy Smith wrote: > The problem is, that doesn't make a whole lot of sense in Python. > The cited implementation uses dicts at each level. By the time > you've done that, you might as well just throw all the data into > one big dict and use the full search string as the key. I

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 1:44 AM, rusi wrote: > It is this need to balance that makes functional programming attractive: > > - implemented like any other programming language > - but also mathematically rigorous Attractive *to the mathematician*. A more imperative style makes sense to someone who'

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 8:16:12 PM UTC+5:30, Roy Smith wrote: > rusi wrote: > > The classic data structure for this is the trie: > > General idea: http://en.wikipedia.org/wiki/Trie > > In python: > > http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ > I agree t

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Grant Edwards
On 2013-12-11, Dennis Lee Bieber wrote: >>That's like saying that when teaching woodwork we shouldn't >>let people use hammers, we should make them use rocks to >>bang nails in, because it will make them better carpenters >>in the long run. > > NAILS > > Nails were verboten in my

Re: load_module for import entire package

2013-12-11 Thread Dave Angel
On Tue, 10 Dec 2013 23:28:31 -0800 (PST), Sergey wrote: def get_obj(): pkg = load_package_strict("tmp", basedir) from tmp import main return main.TTT() It is working, but if package code changes on disc at runtime and I call get_obj again, it returns instance of class, loaded for the

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Roy Smith
In article <3efc283f-419d-41b6-ad20-c2901c3b9...@googlegroups.com>, rusi wrote: > The classic data structure for this is the trie: > General idea: http://en.wikipedia.org/wiki/Trie > In python: > http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I agree that a trie fit

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 5:16:50 PM UTC+5:30, Oscar Benjamin wrote: > The Electrical Engineering students will subsequently do low-level > programming with registers etc. but at the earliest stage we just want > them to think about how algorithms and programs work before going into > all the

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 13:44, Steven D'Aprano wrote: > If necessary, I would consider having 26 dicts, one for each > initial letter: > > data = {} > for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": > data[c] = {} > > then store keys in the particular dict. That way, if I wanted keys > starting with Aa, I woul

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 7:47:34 PM UTC+5:30, Roy Smith wrote: > JL wrote: > > Python scripts can run without a main(). What is the advantage to using a > > main()? Is it necessary to use a main() when the script uses command line > > arguments? (See script below) > > #!/usr/bin/python

  1   2   >