[Tutor] sorting distances for nearest neighbor

2014-08-29 Thread LN A-go-go
Python Gurus, How do you sort distances to prepare for nearest neighbor when the results returned look like this from the below statements? DR=distance(n,XCOORDINATE, YCOORDINATE, IDCODE) DZ=switch(n,XCOORDINATE, YCOORDINATE, IDCODE) Distance from 1 to 16 is 43763.0757603 19 is 126516.988978 1

[Tutor] extracting a cPickle/pickle file from inside a zip file

2014-08-29 Thread diliup gabadamudalige
HI! To all, with open(from_dir + "\\" + name_py,"wb") as outfile: cPickle.dump(str1,outfile) after doing above I zip the file with some other files into a password secured zip file using win rar. I can extract all other files except the py file. pload = cPickle.load(zf.open("my.py",pwd=passw

Re: [Tutor] sorting distances for nearest neighbor

2014-08-29 Thread R. Alan Monroe
> How do you sort distances to prepare for nearest neighbor when the > results returned look like this Have you read up on the "key" parameter for Python's sort() function? You can use that, along with split() to do this. Alan ___ Tutor maillist - Tu

Re: [Tutor] extracting a cPickle/pickle file from inside a zip file

2014-08-29 Thread Alan Gauld
On 29/08/14 10:00, diliup gabadamudalige wrote: pload = cPickle.load(zf.open("my.py",pwd=password)) this gives an EOF . Does any body know why? I've never used zipfile so I don't know, but could it be related to the fact that your pickle file is binary? Do you need any flags to tell zipfile t

Re: [Tutor] sorting distances for nearest neighbor

2014-08-29 Thread Dave Angel
LN A-go-go Wrote in message: > Please tell your email program to use text when posting here, The html you used can cause numerous problems. One of them prevents me from quoting context. If you can get your data to a list of tuples, then you can sort that list by something like sorteddata =

Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
On Thu, Aug 28, 2014 at 6:39 PM, Cameron Simpson wrote: > On 28Aug2014 22:36, Alan Gauld wrote: >> >> On 28/08/14 19:03, leam hall wrote: >>> >>> python 2.4.3 on Red Hat Linux. >>> >>> I'm starting a project and want to break the scripts into "input", >>> "output", and "ddl". I'd like to have a "

Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
On Fri, Aug 29, 2014 at 9:39 AM, diliup gabadamudalige wrote: > this is the easiest way to do this > > # one.py is in the \data\ directory > # two.py is in the \data\img\ directory > # three.py is in the \data\img\sc\ directory > > ## this program is in the learn_music dir > > ## expanding the fil

Re: [Tutor] extracting a cPickle/pickle file from inside a zip file

2014-08-29 Thread diliup gabadamudalige
http://stackoverflow.com/questions/3006727/load-a-pickle-file-from-a-zipfile zf = czipfile.ZipFile(r"cpickletest.zip") pyfromzip = zf.read ("cPickletest.py", pwd="python") print pyfromzip, type(pyfromzip) this prints the following to the console (dp1 S'kola.jpg' p2 S'CSVTQq#w.@lm' p3 sS'p2.jpg'

[Tutor] Python 3.4.1 question for Mac users

2014-08-29 Thread Richard Dillon
I’m teaching myself Python 3.4.1 on a Mac and the book I’m using is written for Windows users. I’m trying to open a file on the desktop and I created a path using the example in the book. Any Mac users out there with a solution? My main drive is named “OS”. Here’s my code: def main()

Re: [Tutor] Python 3.4.1 question for Mac users

2014-08-29 Thread Chris “Kwpolska” Warrick
On Fri, Aug 29, 2014 at 5:01 PM, Richard Dillon wrote: > I’m teaching myself Python 3.4.1 on a Mac and the book I’m using is written > for Windows users. > > I’m trying to open a file on the desktop and I created a path using the > example in the book. > > > > Any Mac users out there with a soluti

Re: [Tutor] Python 3.4.1 question for Mac users

2014-08-29 Thread Chris “Kwpolska” Warrick
Sorry for the errorneous quote-only response, gmail managed to send it without me typing a thing. On Fri, Aug 29, 2014 at 5:01 PM, Richard Dillon wrote: > infile = open(r'\OS\Users\richarddillon\Desktop\my_file','r') On the Mac, you don’t need to specify a drive there; the main drive is just

Re: [Tutor] Python 3.4.1 question for Mac users

2014-08-29 Thread Al Bull
-Original Message- From: Tutor [mailto:tutor-bounces+a.bull=pubdmgroup@python.org] On Behalf Of Chris “Kwpolska” Warrick Sent: Friday, August 29, 2014 11:40 AM To: Richard Dillon Cc: tutor@python.org Subject: Re: [Tutor] Python 3.4.1 question for Mac users Sorry for the errorneous qu

[Tutor] Printing a list count - Help

2014-08-29 Thread Derek Jenkins
Hi everybody, I have a list that I want to go through and finally print a total count of particular items. In this case, I want to print the result of how many A's and B's are in the list. honor_roll_count = 0 student_grades = ["A", "C", "B", "B", "C", "A", "F", "B", "B", "B", "C", "A"] for grad

Re: [Tutor] sorting distances for nearest neighbor

2014-08-29 Thread Danny Yoo
> How do you sort distances to prepare for nearest neighbor when the results > returned look like this from the below statements? It's unclear what you're asking. 1. Are you showing us the file content in the raw form: > Distance from 1 to > 16 is 43763.0757603 > 19 is 126516.988978 > 18 is 1

Re: [Tutor] extracting a cPickle/pickle file from inside a zip file

2014-08-29 Thread Danny Yoo
> now if i do this > > outfile = cStringIO.StringIO() > outfile.write(pyfromzip) > z=cPickle.load(outfile) Do you have to rewind the outfile so that the read is properly positioned? The following interaction: # >>> import StringIO >>> out = StringIO.StringIO() >>> ou

Re: [Tutor] Printing a list count - Help

2014-08-29 Thread Danny Yoo
> > The above code prints 8 lines, each being an entry for which item in > the list was either A or B. Again, I'm looking for the result to be > the number 8 itself - the total number of instances that A or B occurs > in the list. Hi Derek, Hint: the code currently prints a variable within the l

Re: [Tutor] Printing a list count - Help

2014-08-29 Thread Derek Jenkins
honor_roll_count = 0 student_grades = ["A", "C", "B", "B", "C", "A", "F", "B", "B", "B", "C", "A"] for grades in student_grades: if grades == "A" or grades == "B": honor_roll_count = honor_roll_count + 1 print honor_roll_count That works more to my liking. Thanks a million, Danny an

Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
Am I asking the wrong question? How do older apps with older versions of python (2.4.x) separate code into sub-directories? Do they? -- Mind on a Mission ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail

Re: [Tutor] Printing a list count - Help

2014-08-29 Thread Derek Jenkins
Alex, Thanks for taking this one step further! I do appreciate it... +1 On Fri, Aug 29, 2014 at 3:48 PM, Alex Kleider wrote: > On 2014-08-29 12:17, Derek Jenkins wrote: >> >> Hi everybody, >> >> I have a list that I want to go through and finally print a total >> count of particular items. In th

Re: [Tutor] Printing a list count - Help

2014-08-29 Thread Alan Gauld
On 29/08/14 20:17, Derek Jenkins wrote: Hi everybody, I have a list that I want to go through and finally print a total count of particular items. In this case, I want to print the result of how many A's and B's are in the list. honor_roll_count = 0 student_grades = ["A", "C", "B", "B", "C", "A

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Crush
I am now able to print stderr to the screen, however I still can not run conditional statements against stderr. Please see the screenshots(SS) here... https://www.dropbox.com/sh/31wyjtvqymo94uk/AAAZaxwB27nw1nmz7tz69I5La?dl=0 Bo > On Aug 28, 2014, at 6:12 PM, Cameron Simpson wrote: > >> On

Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread Peter Otten
leam hall wrote: > Am I asking the wrong question? How do older apps with older versions > of python (2.4.x) separate code into sub-directories? Do they? Even new versions allow relative imports only inside packages. Given a tree $ tree . ├── alpha │ ├── beta │ │ ├── __init__.py │ │ └─

Re: [Tutor] extracting a cPickle/pickle file from inside a zip file

2014-08-29 Thread Danny Yoo
Hi Dillup, One other comment other than the zipfile stuff: you might want to consider something other than pickle format if you want interchangeability with other tools. JSON, for example, is pretty well-supported in the json library: https://docs.python.org/2/library/json.html and it has

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Danny Yoo
On Fri, Aug 29, 2014 at 2:13 PM, Crush wrote: > I am now able to print stderr to the screen, however I still can not run > conditional statements against stderr. > > Please see the screenshots(SS) here... > > https://www.dropbox.com/sh/31wyjtvqymo94uk/AAAZaxwB27nw1nmz7tz69I5La?dl=0 Hi Bo, Cons

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Danny Yoo
Hi Bo, One other thing: if you can avoid running commands as root, I'd strongly suggest doing so. Your second screenshot shows that you're running as root superuser, and the imaginary security demon that sits on my left shoulder is laughing uproariously as we speak. __

Re: [Tutor] Import from project's lib directory?

2014-08-29 Thread leam hall
On Fri, Aug 29, 2014 at 5:16 PM, Peter Otten <__pete...@web.de> wrote: > leam hall wrote: > >> Am I asking the wrong question? How do older apps with older versions >> of python (2.4.x) separate code into sub-directories? Do they? > You have to ensure that the *parent* of alpha is in sys.path. The

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Crush
Ok so no links to dropbox? Man im confused...i thought links to dropbox were ok? Wow i feel like such an idiot haha. I should have caught that capitolization error! Im sorry to have waisted your time. Bo > On Aug 29, 2014, at 6:06 PM, Danny Yoo wrote: > >> On Fri, Aug 29, 2014 at 2:13 PM,

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Crush
Haha Yes I am aware of people like you who are just itching to exploit vulnerabilities like that; however, the programs my company uses to broadcast will only run as root. Bo > On Aug 29, 2014, at 6:12 PM, Danny Yoo wrote: > > Hi Bo, > > One other thing: if you can avoid running commands a

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Cameron Simpson
On 29Aug2014 18:31, Crush wrote: Ok so no links to dropbox? Man im confused...i thought links to dropbox were ok? That was my fault. I said: If your screenshot is inherently graphical, publish it elsewhere (eg save it to Dropbox and get a "public link") and mention the link in your post

Re: [Tutor] Interacting with stderr

2014-08-29 Thread Cameron Simpson
On 29Aug2014 18:35, Crush wrote: On Aug 29, 2014, at 6:12 PM, Danny Yoo wrote: One other thing: if you can avoid running commands as root, I'd strongly suggest doing so. Your second screenshot shows that you're running as root superuser, and the imaginary security demon that sits on my left sh

[Tutor] Fwd: Re: extracting a cPickle/pickle file from inside a zip file

2014-08-29 Thread Danny Yoo
-- Forwarded message -- From: "diliup gabadamudalige" Date: Aug 29, 2014 8:34 PM Subject: Re: [Tutor] extracting a cPickle/pickle file from inside a zip file To: "Danny Yoo" Cc: Dear Danny, Thank for your invaluable advice which is much appreciated. My code finally ends up being