KeyboardInterrupt when calling a function


I am toying with the following program to generate prime numbers:

(Toggle Plain Text) import sys from math import sqrt, floor def prime_gen(count): num = 2 ct = 0 while ct < count: for i in range(2, int(floor(sqrt(num)))): if num % i == 0: num = num + 1 elif num % i != 0: print num ct = ct + 1 num = num + 1 prime_gen(100) #x = int(sys.argv[1]) #prime_gen(x) import sys from math import sqrt, floor def prime_gen(count): num = 2 ct = 0 while ct < count: for i in range(2, int(floor(sqrt(num)))): if num % i == 0: num = num + 1 elif num % i != 0: print num ct = ct + 1 num = num + 1 prime_gen(100) #x = int(sys.argv[1]) #prime_gen(x)
Posted On: Friday 28th of December 2012 05:24:46 AM Total Views:  209
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




Finding Peoples' Names in Files

Crazy question, but has anyone attempted this or seen Python code that does For example, if a text file contained 'Guido' and or 'Robert' and or 'Susan', then we should return True, otherwise return False.
VIEWS ON THIS POST

27

Posted on:

Monday 5th November 2012
View Replies!

Script to extract text from PDF files

On Wed Sep 26 15:06:54 CEST 2007, byte8bits wrote: > On Sep 25, 10:19 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: > > > This is inherent in the nature of PDF: it's a page-description language, > > not a document-interchange language. Each text-drawing command can put a > > block of text anywhere on the page, so you have no idea, just from > > parsing the PDF content, how to join these blocks up into lines, > > paragraphs, columns etc. > > So (I'm not being a wise guy) how does pdftotext do it so well There's a little information on that online: http://www.glyphandcog.com/textext.html You would need to look at the source code to see exactly what it does. > The text I can extract from PDFs is extracted as it appears in the doc. > Although there are various ways to insert and encode text in PDFs, > it's also well documented in the PDF specifications (http:// > www.adobe.com/devnet/pdf/pdf_reference.html). Just because inserting and encoding is well documented doesn't mean that the reverse processes are easy. :-/ > Going back to pdftotext... it works well at extracting text from PDF. > I'd like a native Python library that does the same. Maybe you should look at the source code for pdftotext, if that's an option. > This can be done. > And, it can be done in Python. I've made a small start, my hope was that > others would be interested in helping, but I can do it on my own > too... it'll just take a lot longer Can I suggest that you approach one or more authors of the existing Python PDF solutions and work with them on this There are at least four PDF parsers written in Python out there. David
VIEWS ON THIS POST

110

Posted on:

Monday 5th November 2012
View Replies!

Re: sort dictionary by specific values

dorje tarap escribi: > 2. > {8: (99, 99), 9: [(55, 67), (77, 66), (67, 88)], 4: [(45, 78), > (56, 78), (99, 78)], 5: (67, 77)} > > > I want to sort the entire dictionary based on the last values in each > line. First for [-1][0] and then[-1][0] Each "line" means each value in the dictionary Did you mean ordering [-1][0] and then [-1][1] Dictionaries cannot be ordered, but you can work with its items (as a list). Your data is not homogeneous (values in the dictionary are both tuples and list of tuples). If you can build it that way: d = {8: [(99, 99)], 9: [(55, 67), (77, 66), (67, 88)], 4: [(45, 78), (56, 78), (99, 78)], 5: [(67, 77)] It would be easy to sort: import operator cmplast = lambda x, y: cmp(x[-1], y[-1]) sorted(d.items(), key=operator.itemgetter(1), cmp=cmplast, reverse=True) or cmplast1 = lambda x, y: cmp(x[1][-1], y[1][-1]) sorted(d.items(), cmp=cmplast1, reverse=True) [(8, [(99, 99)]), (4, [(45, 78), (56, 78), (99, 78)]), (9, [(55, 67), (77, 66), (67, 88)]), (5, [(67, 77)])]
VIEWS ON THIS POST

124

Posted on:

Monday 5th November 2012
View Replies!

Empty string namespace on XP in minidom

Howdy I ran into a difference between Python on Windows XP and Linux Fedora 6. Writing a dom to xml with minidom works on Linux. It gives an error on XP if there is an empty namespace. The problem was handled in CVS a while ago. http://mail.python.org/pipermail/xml...er/009904.html Here is an example on XP Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from xml.dom.minidom import parseString >>> doc = parseString('value') >>> doc.toxml() u'value' >>> doc = parseString('value') >>> doc.toxml() Traceback (most recent call last): File "", line 1, in File "C:\tools\Python25\lib\xml\dom\minidom.py", line 45, in toxml return self.toprettyxml("", "", encoding) File "C:\tools\Python25\lib\xml\dom\minidom.py", line 57, in toprettyxml self.writexml(writer, "", indent, newl, encoding) File "C:\tools\Python25\lib\xml\dom\minidom.py", line 1744, in writexml node.writexml(writer, indent, addindent, newl) File "C:\tools\Python25\lib\xml\dom\minidom.py", line 809, in writexml _write_data(writer, attrs[a_name].value) File "C:\tools\Python25\lib\xml\dom\minidom.py", line 299, in _write_data data = data.replace("&", "&").replace("
VIEWS ON THIS POST

56

Posted on:

Monday 5th November 2012
View Replies!

Re: Problems with regular expressions

En Thu, 14 Jun 2007 21:42:02 -0300, Carlos Luis Prez Alonso escribi: > I have the next piece of code: > ------------------------------------------------------------------------ > if re.search('^(taskid|bugid):\\d+',logMessage): > return 0 > else: > sys.stderr.write("El comentario tiene que contener el > taskid:#### o el bugid:####") > return 1 > ------------------------------------------------------------------------- > The regular exprexin is "^(taskid|bugid):\\d+" > Mi problem is that if logMessage == "taskid:234" the regular expression > matched teorically, but the result is always "None" and the function > returns 1. For "taskid:234" it matches ok: py> re.search('^(taskid|bugid):\\d+',"taskid:1234") py> re.search('^(taskid|bugid):\\d+',"asdfa fa taskid:1234") py> re.search('^(taskid|bugid):\\d+'," taskid:1234") py> re.search('^(taskid|bugid):\\d+',"taskid:123adfa asfa lkjljlj") Because of the ^, it *only* matches at the start of the line. If you want a match anywhere (as implied by your error message), just remove the ^. -- Gabriel Genellina
VIEWS ON THIS POST

243

Posted on:

Monday 5th November 2012
View Replies!

Books about Python.

I'm up to write a 20-30 research paper for my computer science course, and I was considering choosing to do mine on Python. I was curious if anybody knows of any good books about python they could recommend that have more of a technical view rather than a Teach-yourself-in-24-hours type.
VIEWS ON THIS POST

66

Posted on:

Wednesday 7th November 2012
View Replies!

How to Encode String of Raw UTF-8 into Unicode?

Hi , Suppose I start out with a raw string of utf-8 code points. raw_string = "68656E727963" I can coerce it into proper unicode format by slicing out two characters at a time. unicode_string = u"\x68\x65\x6E\x72\x79\x63" >>> print unicode_proper >>> henry My question: is there an existing function that can do this (without having to manually slicing the raw text string)
VIEWS ON THIS POST

46

Posted on:

Wednesday 7th November 2012
View Replies!

System exit hanging in Leopard

, (I posted this once before, but haven't gotten a response. This is a pretty heavy traffic mailing list, so it's hardly surprising, but I'm going to bump the question in case anybody has seen or can replicate (or not replicate) this issue. Thx) I'm using Tkinter to create widgets in Python 2.5 on OS X 10.5. When I call root.quit or sys.exit in any way, the following traceback appears, after which the application stops responding and just gives the spinning rainbow cursor. The IDLE editor and the Python shell remain responsive, and I can kill the application from the command line, but not any other way. I don't see anything problematic in the traceback, but I don't think that the application should be hanging like this. Is this likely a Leopard-related issue
VIEWS ON THIS POST

58

Posted on:

Wednesday 7th November 2012
View Replies!

%s shortcut?

hi i have something like this cursor.execute(""" select c.name, (select from ap_invoice i where Month(i.date) = 1 and Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') jan, (select from ap_invoice i where Month(i.date) = 2 and Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') feb, (select from ap_invoice i where Month(i.date) = 3 and Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') mar from ap_customer c order by %s""", [year, order_by]) what I could like to happen is ... since the first three %s points to the same year variable, how do I let python know it without doing [year ,year, year, order_by] ... This should be 12 I just cut it down
VIEWS ON THIS POST

94

Posted on:

Wednesday 7th November 2012
View Replies!

[ANN] ratfun-2.4 Polynomials and Rational Functions

The ratfun module provides classes for defining polynomial and rational function (ratio of two polynomials) objects. These objects can be used in arithmetic expressions and evaluated at a particular point. Home page: http://calcrpnpy.sourceforge.net/ratfun.html Note: If you are using rpncalc-1.2 or later, this module is already included. This release is for folks who don't want rpncalc. Changes in 2.4 * Updated the included clnum package. * Added uniqueRoots to handle polynomials with multiple roots.
VIEWS ON THIS POST

23

Posted on:

Wednesday 7th November 2012
View Replies!

Get a filename list of a web site

Hi all, is it possible to get a filename directory list of a website (possibly with full path indication) Using python & possibly wget Bye.
VIEWS ON THIS POST

68

Posted on:

Saturday 10th November 2012
View Replies!

What can we do about all the spam that the list is getting?

What can we do about all the spam that comp.lang.python is getting Things are getting pretty bad....
VIEWS ON THIS POST

110

Posted on:

Saturday 10th November 2012
View Replies!

SnakeCard GPL products

Dear all, I have decided to focus my activities on development and support. I have released SnakeCard's produt line source code under the GPL licence www.snakecard.com ) It includes: SCF: SnakeCard Framework (software=Python) SCFB: SnaleCard Framework Bundle (software=Python, applets BasicCard ...
VIEWS ON THIS POST

34

Posted on:

Saturday 10th November 2012
View Replies!

type, object hierarchy?

print dir(type) #__mro__ attribute is in here print dir(object) #no __mro__ attribute class Mammals(object): pass class Dog(Mammals): pass print issubclass(Dog, type) #False print Dog.__mro__ --output:-- (, , ) The output suggests that Dog actually is a subclass ...
VIEWS ON THIS POST

45

Posted on:

Saturday 10th November 2012
View Replies!

CodeInvestigator version 0.7.0

CodeInvestigator version 0.7.0 was released on January 17. A new feature was added: CodeInvestigator helps you return to your code after you have scrolled away from it. Lines are marked so you can locate them and scroll back to them. ...
VIEWS ON THIS POST

42

Posted on:

Saturday 10th November 2012
View Replies!

pass data from optparse to other class instances

I'm writing a command-line interface using optparse. The cli takes several options with a single action and several parameters to be used in the resulting worker classes. I've been passing parameters from optparse to the workers in two ways: ...
VIEWS ON THIS POST

86

Posted on:

Sunday 11th November 2012
View Replies!

Finding Full Path to Process EXE

, I would like to write a script that would enumerate all running processes and return the full path to the EXE of each running process. However, I can't seem to find any good info on how to do this..any ...
VIEWS ON THIS POST

31

Posted on:

Sunday 11th November 2012
View Replies!

Re: how to capture screenshots of the active window in Python

En Thu, 27 Mar 2008 20:28:27 -0300, Praveena B escribi: > Can anyone help me out\t Still lacking details... PIL has a ImageGrab module, Windows only. -- Gabriel Genellina...
VIEWS ON THIS POST

164

Posted on:

Sunday 11th November 2012
View Replies!

questions about named pipe objects...

I'm proceeding slowly though the Lutz book "Programming Python". I'm in the section on named pipes. The script he uses has two functions: one for the child the other for the parent. You start the parent then the child: python ...
VIEWS ON THIS POST

77

Posted on:

Sunday 11th November 2012
View Replies!

Re: system32 directory

Robert Dailey wrote: > > > Is there a way to get the System32 directory from windows through python > For example, in C++ you do this by calling GetSystemDirectory(). Is there an > equivalent Python function for obtaining ...
VIEWS ON THIS POST

266

Posted on:

Sunday 11th November 2012
View Replies!

Re: del self?

Simon Pickles wrote: > > > Just curious... What are the implications of a class member calling: > > del self A method like def spam(self): del self just removes self from the local namespace of the spam function ...
VIEWS ON THIS POST

44

Posted on:

Sunday 11th November 2012
View Replies!

EZ Recipe & Menu Costing

Customized Excel Workbook to Cost Your Recipes & Menu Items http://food-drinks.page.tl/...
VIEWS ON THIS POST

39

Posted on:

Sunday 25th November 2012
View Replies!

Re: Python Written in C?

giveitawhril2008 wrote... > I think someone should write a compiler, "Revenge of BASIC." Your remark made an immediate association with me with the following soundtrack: http://www.empire-of-the-claw.com/fi...aw%20-%20Tranc e%20of%20the%2080's%20Arcade.mp3 "A creature for my amusement" Greetings, -- "The ability of the OSS process ...
VIEWS ON THIS POST

41

Posted on:

Sunday 25th November 2012
View Replies!

How to package a logging.config file?

I'm working on a package that uses the standard library logging module along with a .cfg file. In my code, I use logging.config.fileConfig('/home/matt/mypackage/matt.cfg') to load in the logging config file. However, it seems really obvious to me that this won't ...
VIEWS ON THIS POST

37

Posted on:

Sunday 25th November 2012
View Replies!

origin of error message

hi i was trying to create an image using user selection of a file in tix fileselection box ..and i check for exception like below .... from string import split from os.path import basename .... #this ...
VIEWS ON THIS POST

142

Posted on:

Sunday 25th November 2012
View Replies!

Disabling the magic "last expression" _ variable

A project I'm currently working on uses Turbogears as a framework. I'd like to interact with it using the tg-admin shell. We also use gettext's _() function for internationalization. Now, this function is overwritten in interactive mode, which causes annoying ...
VIEWS ON THIS POST

96

Posted on:

Sunday 25th November 2012
View Replies!

ZFS bindings

Is anyone aware of python bindings for ZFS I just want to replicate (or at least wrap) the command line functionality for interacting with snapshots etc. Searches have turned up nothing. Kris...
VIEWS ON THIS POST

43

Posted on:

Sunday 25th November 2012
View Replies!

Re: The best way to package a Python module?

On Mon, 16 Jun 2008 01:37:47 +0900, js wrote: >On Mon, Jun 16, 2008 at 1:16 AM, Jean-Paul Calderone wrote: >> On Mon, 16 Jun 2008 01:01:47 +0900, js wrote: >>> >>> Hi list, >>> >>> I'm ...
VIEWS ON THIS POST

90

Posted on:

Sunday 25th November 2012
View Replies!

Re: How to remove read-only from a file

Robert Dailey wrote: > > > Using Python 3.0, how can I remove a read-only property from a file in > Windows XP
VIEWS ON THIS POST

123

Posted on:

Sunday 25th November 2012
View Replies!

Database Query Contains Old Data

, I'm having a problem with the Python db api, using MySQL. I've written a program with a GUI using wxPython, the GUI is contained in main.py which imports another module - reports.py. There are several reports that are ...
VIEWS ON THIS POST

36

Posted on:

Sunday 25th November 2012
View Replies!

ANN: Python FTP Server library (pyftpdlib) 0.4.0 released

I'm pleased to announce release 0.4.0 of Python FTP Server library (pyftpdlib). http://code.google.com/p/pyftpdlib/ === About === Python FTP server library provides an high-level portable interface to easily write asynchronous FTP servers with Python. Based on asyncore framework pyftpdlib is ...
VIEWS ON THIS POST

112

Posted on:

Sunday 25th November 2012
View Replies!

Announcing a feature update (v1.3) of YaMA, the meeting assistant

Yet Another Meeting Assistant (YaMA), will help you with the Agenda, Meeting Invitations, Minutes of a Meeting as well as Action Items. If you are the assigned minute taker at any meeting, this tool is for you. Checkout http://yama.sourceforge.net/ ...
VIEWS ON THIS POST

94

Posted on:

Sunday 25th November 2012
View Replies!

Dynamic generation of images (was Re: Custom Classes?)

On Thu, 2008-05-08 at 10:33 -0500, Victor Subervi wrote: > Okay, trying this again with everything working and no ValueError or > any other errors, here we go: > > Load this code. Unless you use a similar login() script, ...
VIEWS ON THIS POST

40

Posted on:

Sunday 25th November 2012
View Replies!

Best way to store config or preferences in a multi-platform way.

python beginner starting a new project here. This project will store most of its actual data in a shared-database, but I have a small amount of user specific data that I need to be stored like configuration or preferences ...
VIEWS ON THIS POST

70

Posted on:

Sunday 25th November 2012
View Replies!

sampling without replacement

Greetings -- I am doing a sampling without replacement, taking out random elements from an array. The picked element is then removed from the array. When my arrays were on the order of 10,000 elements long, everything was fast. But ...
VIEWS ON THIS POST

90

Posted on:

Sunday 25th November 2012
View Replies!

Classes in modules

I'm trying to get this source code split into multiple files: http://pygermanwhist.googlecode.com/...manwhist.12.py I've been trying to make so that I have one class per file for easier readability. My problem is that the interpreter keeps saying that it can't find ...
VIEWS ON THIS POST

34

Posted on:

Sunday 25th November 2012
View Replies!

message entry box at center

from Tkinter import * def callback(): print e.get() master=Tk() e=Entry(master) e.pack(anchor=CENTER) e.focus_set() b=Button(master,text="get",width=10,command=callback) b.pack(anchor=CENTER) master.mainloop() i want to show the entry button at the center of the window. How is it possible \t...
VIEWS ON THIS POST

73

Posted on:

Sunday 25th November 2012
View Replies!

smtpd module

, the documentation of the smtpd module in the Python Library Reference is very short, I think. Are there any examples available Especially I'm interested in the DebuggingServer.
VIEWS ON THIS POST

50

Posted on:

Sunday 25th November 2012
View Replies!

Re: Python and binary compatibility

> my troubles could apparently be fixed if I > could acquire a copy of VS 2003, but Microsoft has made it incredibly > difficult to find the download for it (I don't think it exists). > > Any ...
VIEWS ON THIS POST

36

Posted on:

Sunday 25th November 2012
View Replies!

paging in python shell

, Does anyone know if the python shell supports paging or if I should look into iPython Thank you so much. Alex...
VIEWS ON THIS POST

103

Posted on:

Sunday 25th November 2012
View Replies!

Any interest in an SQS alternative???

I'm a big fan of Amazon's SQS web services. However, I think their SQS is simply too expensive. I was doing some tests in python using SQS and created 1,513 messages in just a few minutes. Then I looked at ...
VIEWS ON THIS POST

87

Posted on:

Monday 26th November 2012
View Replies!

gtk.TreeView cell inconsistent state

In the below code setting cell to inconsistent sets entire column inconsistent (renderer).However, I need a third state off | on | inconsistent . How can I change one path->cell
VIEWS ON THIS POST

123

Posted on:

Monday 26th November 2012
View Replies!

pipeline encoding

My locale is set to UTF-8. The command: python -c "print u'\u03A9'" gives me the deed result and doesn't produce any error. But when I want to redirect the output to a file I invoke: python -c "print u'\u03A9'" > ...
VIEWS ON THIS POST

59

Posted on:

Monday 26th November 2012
View Replies!

Create thumbnail image (jpg/png) of PDF file using Python

Is there any way to do this directly within python If not is there any other good way to achieve it
VIEWS ON THIS POST

61

Posted on:

Monday 26th November 2012
View Replies!

Need Help writing simple program

, I'm new here and I'm a complete n00b to Python and programming in general. I'm trying to write a program, cuz there's all of these beginner challenges on the ubuntu forums and I'm trying to do them. Anyway, here is the program I'm trying to run (Toggle Plain Text) import sys print ", I'm going to ask you a few questions. And this isn't interrogation lol.\n\nP.S. Type 'exit' without the quotes at any prompt in order to leave/quit." def forum_name(): forum_name = raw_input("What is your forum name \(the name you login with, and the name people see on your posts \)> ") if len(forum_name) > 20: print "False, user names can't be more than 20 characters!" forum_name() elif len(forum_name) 20: import sys print ", I'm going to ask you a few questions. And this isn't interrogation lol.\n\nP.S. Type 'exit' without the quotes at any prompt in order to leave/quit." def forum_name(): forum_name = raw_input("What is your forum name \(the name you login with, and the name people see on your posts \)> ") if len(forum_name) > 20: print "False, user names can't be more than 20 characters!" forum_name() elif len(forum_name) 20:
VIEWS ON THIS POST

50

Posted on:

Tuesday 27th November 2012
View Replies!

I've been trying to utilize Python import hooks.

And I can't get anything I write to work. I'm so far off course I think I just need a working example of import hooks in action. I've looked for examples on the Internet, but they only show what looks like correct code. They never show that code in action. They never try to import something and show what their hook does.
VIEWS ON THIS POST

109

Posted on:

Tuesday 27th November 2012
View Replies!

Need help adding a loop to restart program

So, I can't seem to get any loop to work in with this program to calculate average test scores. This is for a lab i need to finish by tomorrow so I need urgent help haha. so far this is what I have; (Toggle Plain Text) score = 0 totalScores = 0 averageScores = 0 students = raw_input("How many students took the test") students = int(students) for counter in range( students ): score = input("Enter a score") totalScores = score + totalScores averageScores = totalScores/students print"The average test score is:",averageScores score = 0 totalScores = 0 averageScores = 0 students = raw_input("How many students took the test") students = int(students) for counter in range( students ): score = input("Enter a score") totalScores = score + totalScores averageScores = totalScores/students print"The average test score is:",averageScores
VIEWS ON THIS POST

119

Posted on:

Tuesday 27th November 2012
View Replies!

GB, GB on disk, Number of folders, Number of files

Hi . Question I use windows xp pro and trying to get through python script the following layout (of course with datas and one space between '':'' and first number) in .doc OR .txt (doesn't matter which): Internal Hard Drive: GB Used: GB Unused: Folder ''XXX'' (Internal Hard Drive): GB Used: GB On Disk Used: Number Of Files: Number Of Folders: Number Of Folders With ''(!!!!!)'' Tag: External Hard Drive (folder ''XXX''): GB Used: GB On Disk Used: Number Of Files: Number Of Folders: ----------------- Where I said ''XXX'' i meant name of the folder. With ''Number Of Folders With ''(!!!!!)'' Tag:'' I meant the number of folders that end (their names) with this tag. Before ''('' is always one space added. I would also like to know: Is it possible that python script automatically ''see'' when external hard drive is connected (usb port) Of course I would have to connect it before running the script. If yes when using the path to the second ''XXX'', I wouldn't need to use the letter of external hard drive, otherwise I would have to, correct Any ideas how could I get, through the script, this file - of course with datas Thank you and best wishes to .
VIEWS ON THIS POST

61

Posted on:

Wednesday 28th November 2012
View Replies!

Need help

i want to learn python, would anybody please give me a small tutorial that shows how to write,save,compile and execute the program.
VIEWS ON THIS POST

75

Posted on:

Wednesday 28th November 2012
View Replies!

Python's Best Web Development Framework's Book Is Now Available!

The first book for CherryPy, the best web development framework for Python, is now available for discounted pre-order. http://www.packtpub.com/CherryPy/book CherryPy's one of my favourite libraries, perfect for launching Python applications on the net. In fact, I even use it more than PHP, and truly believe it to be better than a PHP, MySQL, Apache combo. This book covers everything on CherryPy 3.0. If anyone's planning to try out CherryPy, now would be a good time with the era of 3.0 and a new book coupled with it. Prepare to see a huge boost in popularity from this little titan. For any that aren't too serious about the scene, you can still read the documentation and use the library, free of charge and without copyright acknowledgement required. I recommend anyone who runs a website, and knows Python, to give it a try.
VIEWS ON THIS POST

92

Posted on:

Friday 28th December 2012
View Replies!