Re: [Tutor] equality check difference

2014-04-19 Thread Chris Fuller
Something I forgot to add. This idea of side-effects with the conditionals is actually the whole point of the Python built-in functinos any() and all(). any() will evaluate a generator expression and stops when one of them evaluates to True, and all() works the same, but stops when a False is

Re: [Tutor] equality check difference

2014-04-19 Thread Chris Fuller
On Saturday, April 19, 2014, Vipul Sharma wrote: > Hello, > > Suppose we want some block of code to be executed when both '*a'* and > '*b'*are equal to say 5. Then we can write like : > > *if a == 5 and b == 5:* > *# do something* > > But a few days ago, I just involuntarily wrote a similar

Re: [Tutor] producing PDF files

2013-06-16 Thread Chris Fuller
On Tuesday, June 11, 2013, Khalid Al-Ghamdi wrote: > Hi, > > Do you know of a python module for converting text files to PDF format? > > thanks Another one, that I've used extensively, is ReportLab. http://www.reportlab.com/software/opensource/ Cheers ___

Re: [Tutor] Socket Programming

2013-04-05 Thread Chris Fuller
Have you checked out the socket HOWTO? http://docs.python.org/2/howto/sockets.html Cheers On Friday, April 05, 2013, Mousumi Basu wrote: > I want to perform bind function for socket programming between two > computers of ip addresses- 172.18.2.11 and 172.18.2.95 using the following > command(on

Re: [Tutor] Fwd: Which databases allow lists as record fields?

2013-03-13 Thread Chris Fuller
Use pickle to serialize the list, then use any DB that takes strings of arbitrary length. You will probably be frustrated if you seek a (useful) DB that has native support for such things. Cheers On Wednesday, March 13, 2013, Dave Angel wrote: > I presume you meant this for the tutor list. I

Re: [Tutor] Dynamic TKinter widgets?

2012-11-24 Thread Chris Fuller
ook" widget class? > On Nov 24, 2012 10:33 PM, "Chris Fuller" > > wrote: > > On Saturday 24 November 2012, Nathan wrote: > > > I'm working on a simple Tarot reading program in Python 2.7, and I'm > > > > having > > > > > a b

Re: [Tutor] Dynamic TKinter widgets?

2012-11-24 Thread Chris Fuller
On Saturday 24 November 2012, Nathan wrote: > I'm working on a simple Tarot reading program in Python 2.7, and I'm having > a bit of trouble with some GUI abstract. (Sorry, no code in here.) > > As of right now, all of the logic is working, and I can generate Tarot > spreads that tell me, in text,

Re: [Tutor] combining c and python

2012-09-17 Thread Chris Fuller
The official documentation covers this in some detail: http://docs.python.org/extending/ http://docs.python.org/c-api/ Cython is an alternate implementation of Python. It's more of a blending of Python and C. It won't, in general, run Python source code or your favorite third-party library. To

Re: [Tutor] Coding Challenges

2012-05-21 Thread Chris Fuller
On Monday 21 May 2012, Martin A. Brown wrote: > Hello, > > : Being new to programming, I've found that my learning is > : accelerated when I've been asked to write scripts and deliver > : them in a specified time frame...Then, have those scripts > : critiqued. > : > : My question: Would the

Re: [Tutor] how to build a multiplayer game?

2012-04-11 Thread Chris Fuller
I think you're on the right track with the IRC idea, but start with something simpler. You can find tutorials or working programs using the asynchat module to make a really basic chat client. Then you build a higher level protocol on top of that. It should take care of most of the low level

Re: [Tutor] Help Glade Tutorial.

2012-01-29 Thread Chris Fuller
Which ones did you look at, and why did you not like them? Keep in mind that Glade is an interface builder, and hasn't got anything much to do with the target language, other than requiring there be a libglade library to read the XML files. I actually got started with some articles in Linux J

Re: [Tutor] Subclassing Exceptions

2012-01-09 Thread Chris Fuller
On Friday 06 January 2012, Steven D'Aprano wrote: > Chris Fuller wrote: > >>>> class Foo(SyntaxError): > > ... def __init__(self, a,b,c): > > ... self.args = (a,b,c) > > ... > > > >>>> raise Foo(1,2,3) > > > > Traceback

Re: [Tutor] making a custom file parser?

2012-01-07 Thread Chris Fuller
If it's unambiguous as to which tags are closed and which are not, then it's pretty easy to preprocess the file into valid XML. Scan for the naughty bits (single quotes) and insert escape characters, replace with something else, etc., then scan for the unterminated tags and throw in a "/" at t

[Tutor] Subclassing Exceptions

2012-01-06 Thread Chris Fuller
I had an interesting experience today. Python 2.7.1 (r271:86832, Nov 28 2010, 19:31:37) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(Exception): ... def __init__(self, a,b,c): ... self.args = (a,b,c) ... >>> raise Foo(1,2,3) Traceb

Re: [Tutor] interesting behaviour with postional output

2011-11-14 Thread Chris Fuller
Fonts can be categorized as "fixed" or "proportional" widths. Proportional width fonts have different widths depending on the character. If you want to line up text, you must use fixed width fonts like courier, or use tabs, but that can be unreliable. You can get fancy and measure the width

Re: [Tutor] where to look for python codes

2011-09-29 Thread Chris Fuller
Unless you are explicitly reading a tutorial, the code you will be looking at isn't going to be beginner-level in general, but you can look at smaller snippets and libraries then work up from that. http://effbot.org/zone/ http://code.activestate.com/recipes/langs/python/ http://pypi.python.org/

Re: [Tutor] integrating python and C

2011-09-23 Thread Chris Fuller
Sudoku is actually a pretty easy problem computationally, I'd do the whole thing in Python, unless you aren't as comfortable doing fancy algorithms (usually easier, anyway, unless you aren't used to the language, or really need static typing) in Python.. but then this would be a good opportunit

Re: [Tutor] Is there a test for hashability?

2011-09-01 Thread Chris Fuller
On Thursday 01 September 2011, Richard D. Moores wrote: > On Thu, Sep 1, 2011 at 12:29, Chris Fuller > > wrote: > > *Ahem* > > > > def is_hashable(object): > > try: > >hash(object) > >except TypeError: > >return False &g

Re: [Tutor] Is there a test for hashability?

2011-09-01 Thread Chris Fuller
On Thursday 01 September 2011, Chris Fuller wrote: > On Thursday 01 September 2011, Richard D. Moores wrote: > > Thanks, James, from your ideas I've come up with this function as a > > general test for hashibility of any object: > > > > def is_hashable(object):

Re: [Tutor] Is there a test for hashability?

2011-09-01 Thread Chris Fuller
On Thursday 01 September 2011, Richard D. Moores wrote: > Thanks, James, from your ideas I've come up with this function as a > general test for hashibility of any object: > > def is_hashable(object): > try: > if hash(object): > return True > except TypeError: >

Re: [Tutor] Fwd: Re: largest palindrome number

2011-08-30 Thread Chris Fuller
I played around with this puzzle a bit. I made a palindrome function a bit like Bob's, only i iterated through the string (stopping at the first mismatch) instead of doing the whole thing at once. The rest of the code is even more amenable to speedups. The first thing I saw was the outer "i"

Re: [Tutor] precision?

2011-08-09 Thread Chris Fuller
There's the one that comes with Python: http://docs.python.org/library/functions.html#round You should consider working with integers, though. Multiply all the values by 1000 and drop the fractional part. Cheers On Tuesday 09 August 2011, Shwinn Ricci wrote: > When comparing a given value wit

Re: [Tutor] broken script - curiouser and curiouser

2011-07-07 Thread Chris Fuller
TWO HOURS?? You aren't a Real Programmer (http://www.catb.org/jargon/html/story-of-mel.html) until you've spent a whole day debugging something trivial. Heck, I quite recently spent a day plus trying to figure out why my microcontroller project wasn't working right. I was using a command line

Re: [Tutor] serial device emulator

2011-07-04 Thread Chris Fuller
You don't need to emulate a serial port (since you're writing the code; you'd have to emulate the port if it was standalone software), only your serial port library. Write a class that has the same methods as the serial port library you're using (you only need the methods you're using or think

Re: [Tutor] Excited about python

2011-06-10 Thread Chris Fuller
For a handy reference, you can't beat "Python Essential Reference" by David Beazley (along with the online documentation, of course!). I think this book is obligatory if you are going to be working with Python a lot. I own all four editions :) But you wanted something more in depth with alg

Re: [Tutor] cpython

2011-05-12 Thread Chris Fuller
CPython refers to the main implementation, which is written in C. There are a bunch of different implementations, such as IronPython for .NET or Jython for the Java Virtual Machine. There's also Cython (subtle spelling difference), which you can use to combine C and Python code. It isn't quit

Re: [Tutor] Recommendation for Pygame

2011-03-01 Thread Chris Fuller
http://www.pyweek.org/ Cheers On Tuesday 01 March 2011, ANKUR AGGARWAL wrote: > Hey > Any good recommendation (ebook,links,videos,Live Example) to get started > with the pygame api. I am totally new to pygame. > Thanks in advance. Waiting for the suggestions :):) > Ankur Aggarwal __

Re: [Tutor] Python in MATLAB

2011-02-25 Thread Chris Fuller
Absolutely. You can use mex files to interface with the Python API (this requires considerable C proficiency), or you can use something like pymex or pymat. Did you google "matlab python"? http://vader.cse.lehigh.edu/~perkins/pymex.html http://claymore.engineer.gvsu.edu/~steriana/Python/pymat

Re: [Tutor] accessing another system's environment

2011-02-25 Thread Chris Fuller
My "etc" would be the loopback device and an iso image, optionally accompanied by wget and cdrecord (or whatever the kids are using these days). I was also reminded of this story: http://thedailywtf.com/Articles/ITAPPMONROBOT.aspx Cheers On Friday 25 February 2011, Corey Richardson wrote: > On

Re: [Tutor] licensing python work?

2011-02-23 Thread Chris Fuller
Invoking the public domain isn't as simple as you might naively think. Tread with care! http://www.linuxjournal.com/article/6225 Cheers On Wednesday 23 February 2011, Wayne Werner wrote: > If you don't care how people use it at all, just release your code into the > public domain, then it do

Re: [Tutor] licensing python work?

2011-02-23 Thread Chris Fuller
I'd recommend the Apache license, for BSD/X11/MIT type permissive licensing, because it's compatible with contributions to Python (maybe not this code, but you might want to contribute something else in the future). http://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq#Contributing_Cod

Re: [Tutor] Py script conversion to .dll or .exe

2011-02-15 Thread Chris Fuller
Python already is a dll; You can load the Python26.dll and use it to run CPython programs with full compatibility. It would be more elegant to use IronPython if if you aren't using any compiled libraries; it would integrate neatly and not be running islolated/standalone. Cheers On Monday 14

Re: [Tutor] Opening and closing SQLite db

2010-12-26 Thread Chris Fuller
You can call the commit() method of the connection object to ensure that any changes are saved to disk, but it's strictly optional. Closely/reopening is not necessary. Cheers On Sunday 26 December 2010, Timo wrote: > Hello, I use SQLite in my application as database, but I think I'm doing > s

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-20 Thread Chris Fuller
This isn't XML, it's an abomination of XML. Best to not treat it as XML. Good thing you're only after one class of tags. Here's what I'd do. I'll give a general solution, but there are two parameters / four cases that could make the code simpler, I'll just point them out at the end. Iterat

Re: [Tutor] Python vs. MATLAB

2010-12-06 Thread Chris Fuller
It also makes it hard to modify some data structure you are working with. I was experimenting with some object-oriented programming in Matlab, and you actually have to explicitly inherit from "handle" if you have any methods that modify internal state. That was a surprise! If you've got a da

Re: [Tutor] Python vs. MATLAB

2010-12-06 Thread Chris Fuller
1) Python is free! 2) Python indices start at 0! 3) Python has way better GUIs 4) Python can emulate a lot of Matlab functionality with matplotlib and numpy 5) Matlab has a rather limited number of data structures 6) Matlab doesn't have anything like the third party support for almost anything 7)

Re: [Tutor] data structures

2010-12-01 Thread Chris Fuller
It sounds to me like all you need is for the values to be another dictionary, keyed on filename? Don't use globals if you can help it. You should be able to structure your program such that they aren't necessary. Something like this? features = { feature1': {'file1': 12, 'file2': 0, 'fil

Re: [Tutor] Random Number Question

2010-11-25 Thread Chris Fuller
Well, you can try "import x", but your problem wasn't that you used the same filename as some Python script on your path, the problem was you then tried to import that other script. So to avoid infinite recursion, all you have to do is avoid importing your own filename, which should be easy en

Re: [Tutor] variable numbers of for loops (also iteration/recursion)

2010-11-23 Thread Chris Fuller
You can always substitute Iteration for Recursion by making the stack an explicit part of your code. As an example, imagine you are traversing this directory tree: birds birds/owls birds/owls/snowy birds/owls/barn birds/owls/great-horned birds/eagles birds/eagles/golden birds/eagles/bald birds/e

Re: [Tutor] Moving my C++ code to Python?

2010-10-15 Thread Chris Fuller
SWIG supports opaque pointers that you can pass into and out of Python without any problems. Working with SWIG isn't that bad for basic stuff, although it can get complicated if you need to have it interpret exotica like references, structures, or such for Python. Having a good C++ background

Re: [Tutor] system()? popen2()? How to execute a command & save its output?

2010-09-29 Thread Chris Fuller
You might also consider pexpect. http://pexpect.sourceforge.net/ It's designed for interactive console applications like ftp. For popen() style access, the recommended approach is the subprocess module. You should be able to find an example in the docs to fit your application. http://docs.pyth

Re: [Tutor] Plotting a Linear Equation

2010-09-25 Thread Chris Fuller
It sounds to me like you need to set a nonzero linewidth. The default is to not fill in the space between points. Check out the documentation at http://matplotlib.sourceforge.net/contents.html. It's a lot to wade through, but worth it when you learn how to unlock the power of the software.

Re: [Tutor] a graceful program exit

2010-08-12 Thread Chris Fuller
The preferred and most graceful way is to use neither, as others have pointed out. However, you can't return an exit code that way, and it sometimes isn't feasible to structure your code to allow it. I prefer SystemExit, because it doesn't require adding something to the namespace (the sys mo

Re: [Tutor] Distributing Python Code for Commercial Porpoises?

2010-08-06 Thread Chris Fuller
It sounds like maybe you could use Enthought Python, which is a bundle of most of the popular numerical libraries by the scipy sponsors. Not free, however, there's a trial version. http://enthought.com/products/epd.php The problem of bundling stuff is a real thorny one and has been beaten to

Re: [Tutor] how to do excel in python

2010-08-05 Thread Chris Fuller
There are many ways. The simplest is to export the file to CSV and load that, but you'll only get one worksheet, and it's a big hassle to update the Excel file that way. You can save the spreadsheet as an ODF file, which is a fully documented XML format that Python can read and write easily,

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller
Sorry, should have included a concrete example. Although, as the others have said, I'm not sure how it helps with what you (seem) to want to do. 0 % cat bar.py def the_answer(self): return 42 0 % cat foo.py import bar class A: pass setattr(A, '__call__', bar.the_answer) a=A() print a(

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller
This actually isn't so hard with classes (not instances of the class). Just use setattr(). The first parameter of the function will be the instance, called "self" by convention. This should work with both old and new style There's stuff in the new module for adding stuff to instances, but I

Re: [Tutor] Linux lib path

2010-04-10 Thread Chris Fuller
I'm using Debian. Used to be etch, but I did a double dist-upgrade recently. So, whatever the current testing release is. My shell is zsh, but bash should work the same. PYTHONPATH should have worked. CLASSPATH is for Java. Here's the documentation link you want: http://docs.python.org/i

Re: [Tutor] recursive generator

2010-03-07 Thread Chris Fuller
Here's a (more or less) useful example. It generates the "nth triangular series" (my term), n=2 is the triangular numbers, n=3 the tetrahedral numbers (n has a correspondence to dimension). Each series is the sum of the elements of the previous one. They are also the columns of Pascal's Tria

Re: [Tutor] Compile py to exe in ubuntu

2010-02-10 Thread Chris Fuller
Using freeze or another tool of its ilk is only going to make you an executable for that platform. If you want an executable for a different platform, you need to set up a native Python environment with all the dependencies installed where Python can find them, and then use that platform's to

Re: [Tutor] packing up python code to transfer to another machine

2010-02-10 Thread Chris Fuller
There are two obvious "gotchas". One is binary extensions. If you are using modules that are not "pure Python", you will have to find *nux versions for your target. The other problem is impossible to solve in general, but most of the time, it's less trouble than the first problem. Python is

Re: [Tutor] python and sqlite

2010-01-31 Thread Chris Fuller
Since v2.5, SQLite is included in the Standard Library. You can get docs at the Python website, or in the handy chm that comes with the Windows distribution. Cheers On Sunday 31 January 2010, Samuel de Champlain wrote: > My project is relatively light and postgresql or mysql might be overkill

Re: [Tutor] No beep from winsound.Beep(500, 500)

2009-12-19 Thread Chris Fuller
Something to keep in mind is that the audio output of your computer and the system speaker are independent. Sometimes the BELL character (ACSII 0x07) will sound the system speaker, spending on your OS, drivers, etc. The winsound docs say it's the speaker, which is connected to the motherboard

Re: [Tutor] working with bit arrays

2009-12-02 Thread Chris Fuller
My approach has been to store it as an array and then build the integer as needed. This code requires Python 2.5 or later. def bits2int(l): return sum([2**i if j else 0 for i,j in enumerate(l)]) To convert the other way: def int2bits(m, n): return [int(bool(m&(1<>= inc return i flo

Re: [Tutor] PyQT forum?

2009-10-29 Thread Chris Fuller
Start with the main site. There are links to wikis/mailing lists/etc there. http://www.riverbankcomputing.co.uk/software/pyqt/ Also, you might be interested in the fully-free alternate, PySide, sponsored by Nokia: http://www.pyside.org/ Cheers On Wednesday 28 October 2009 11:17, Christopher S

Re: [Tutor] PyGTK: is there a library for both Linux and Windows

2009-10-21 Thread Chris Fuller
on differences: The downloads include binaries, so there have to be distinct files for Linux and Windoze. If you download the same versions, there shouldn't be any noticeable differences, with one big exception: multithreading and PyGTK don't mix well on Windows. Your application might run

Re: [Tutor] PyGTK: is there a library for both Linux and Windows

2009-10-21 Thread Chris Fuller
The version of GTK for windows I like to use is at http://gladewin32.sourceforge.net/, but it is rather out of date. It's main advantage is everything is bundled up in a nice installer. You can also get it from the main site at ftp://ftp.gtk.org/pub/gtk, but you have to grab several files an

Re: [Tutor] cannot convert eps to png using PIL (LL)

2009-10-17 Thread Chris Fuller
Like I said, you need to find out what's going wrong with GhostScript. Also, converting image formats is something PIL does internally, without requiring a (large) external package like GhostScript, which is an interpreter for a different language (PostScript), which your eps files are coded i

Re: [Tutor] cannot convert eps to png using PIL

2009-10-15 Thread Chris Fuller
It's trying to launch GhostScript, and failing. The broken pipe is a clue that its trying to communicate with external software. Most likely, you don't have ghostscript installed. Google Ghostscript and you should find instructions for installing on windows (I'm fairly sure there is a port).

Re: [Tutor] Wrapper of C++

2009-10-08 Thread Chris Fuller
It might also be a good application for numpy (http://www.numpy.org/) Cheers ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Pyduino

2009-09-07 Thread Chris Fuller
There are a few projects attempting something like this, but it is not easy to get a language like Python running on the minimalist resources found in a microcontroller. Google "python microcontroller" (without the quotes).. you could also try the plural form to see if that brings up other hits

Re: [Tutor] this module

2009-08-08 Thread Chris Fuller
Something else to note: you can find any module's location by looking it up in the dictionary sys.modules. For instance: Python 2.4.4 (#2, Oct 22 2008, 19:52:44) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >

Re: [Tutor] this module

2009-08-08 Thread Chris Fuller
On Friday 07 August 2009 21:31, Mark Young wrote: > Hi, I was reading a tutorial, and it mentioned the "import this" easter > egg. I was curious, and looked up the contents of the module, and dscovered > that it had attributes c, d, i, and s. I was wondering if anyone had any > clue what these attr

Re: [Tutor] Program to Simulate Keystrokes

2009-08-04 Thread Chris Fuller
On Tuesday 04 August 2009 12:43, Megan Land wrote: > Hi, > > I'm working on a python script to automate a program we run at work. The > program is run from one command. The only problem is that it asks you to > hit enter to continue after it runs. Is there a way I can do this? > > If at all poss

Re: [Tutor] how to know if process is running?

2009-07-28 Thread Chris Fuller
On Tuesday 28 July 2009 10:45, shawn bright wrote: > Hey all, > > I have an app that runs in a GUI written in pygtk. It spawns several > threads, and runs all the time. > It is mission critical that we can never have two instances of this > running at once. > > So, my question is, how can i write s

Re: [Tutor] segmentation fault

2009-07-12 Thread Chris Fuller
On Sunday 12 July 2009 11:09, Rick Pasotto wrote: > I've got a script that I wrote several years ago and have been happily > using daily. Suddenly when I try to run it I get a segmentation fault. > > I'm running debian testing so probably some recent update caused the > breakage. How can I find out

Re: [Tutor] int to bytes and the other way around

2009-07-06 Thread Chris Fuller
The only things that matter are the arguments and the result. It sounds to me like a good case use for SWIG (http:://www.swig.org). You can do really complicated stuff with swig, and it takes a correspondingly steep learning curve to achieve, but doing simple stuff is really simple. It sounds

Re: [Tutor] list comprehension problem

2009-07-03 Thread Chris Fuller
On Friday 03 July 2009 15:37, Emile van Sebille wrote: > On 7/3/2009 1:21 PM Kent Johnson said... > > > On Fri, Jul 3, 2009 at 3:49 PM, Dinesh B > > > > Vadhia wrote: > >> d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] > >> > >> and we want: > >> > >> [0, 8, 12, 16, 20, 27, 29,

Re: [Tutor] how to manage an encrypted file?

2009-06-19 Thread Chris Fuller
On Friday 19 June 2009 17:23, Robert Lummis wrote: > Could you recommend a module or methods I should use to manage an > encrypted text file? I want to store passwords and associated contact > information in a file and feel confident that if the file is stolen > the information couldn't be read. U

Re: [Tutor] distutils MANIFEST.in

2009-06-17 Thread Chris Fuller
Use os.path.walk or similar to build the file before you call setup(). Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Best Python Editor

2009-06-13 Thread Chris Fuller
On Saturday 13 June 2009 04:44, Eddie wrote: > Hi guys, > > What would you regard as the best free Python editor to use on Windows > for a new guy? Searching Google i see that there is quite a few out > there and is "VIM" the best one to go with? > > Regards > Eddie I've tried a lot of editors, an

Re: [Tutor] split or replace

2009-06-05 Thread Chris Fuller
On Friday 05 June 2009 06:18, Norman Khine wrote: > Hello, > What is the way to group each value so that I get a list, from a string > like: > > dir = '/expert/forum/expert/expert' > list = ['/expert', '/forum', '/expert', '/expert'] > > I've tried: > >>> dir = '/expert/forum' > >>> dir.split('/')

Re: [Tutor] Number cruncher

2009-04-22 Thread Chris Fuller
Most teachers use spreadsheets for this. Is there a reason you'd like to use Python? A spreadsheet would be easier to create and less error prone. If you don't have a copy of Microsoft Orifice handy, you can use Gnumeric or Open Office. Cheers On Wednesday 22 April 2009 10:54, John Jenkinson

Re: [Tutor] Functional Derivatives

2009-04-20 Thread Chris Fuller
His problem was composing four functions, each with a small error. The first two applications work well enough, but there is a about a percent error in the third composition. The big source of error is f(x+h)-f(x). Subtracting two floating point numbers that are nearly equal is a known source

Re: [Tutor] Functional Derivatives

2009-04-20 Thread Chris Fuller
You should look up "numerical methods" or similar. There are ways of rearranging your calculations to minimize the loss of precision. You could also try a numerical/scientific library like GMP (for integers or rational numbers). I don't know of any (Python) library for extended precision fl

Re: [Tutor] Using C in python

2009-03-25 Thread Chris Fuller
There's a section in the Python docs just on this topic: http://docs.python.org/extending/index.html There's probably also some stuff in the wiki, although I'm not familiar with anything specific: http://wiki.python.org/moin/ The SWIG documentation is extensive, and while not the user-friendl

Re: [Tutor] adding dictionary values

2009-03-20 Thread Chris Fuller
Oops! The dictionary iterates over keys, not values as I stated (and demonstrated by your working code). Consequently, the example I gave could be more succinctly expressed by: sa = set(a) sb = set(b) Sorry for the error. Cheers ___ Tutor maillist -

Re: [Tutor] adding dictionary values

2009-03-20 Thread Chris Fuller
You should iterate over the keys of the dictionary: for k in a.keys(): because if you iterate over the full dictionary, your items are the values, not the keys. Otherwise your code looks correct, and I don't think its terribly bad form. You could do something interesting with sets: sa = set(a.k

Re: [Tutor] Tkinter Geometry Management and Other Basics

2009-03-19 Thread Chris Fuller
With respect to grid and pack, all siblings must use the same manager. Do otherwise and your application will hang. Children/parents may use different managers. I don't believe there are any restrictions on place, as it doesn't do any negotiation. Cheers _

Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?

2009-03-17 Thread Chris Fuller
widget), includes a set of standard data validators, etc. Cheers On Tuesday 17 March 2009 16:27, Alan Gauld wrote: > "Chris Fuller" wrote > > This book does not cover the Tix widget set, which was originally > > created for > > Tcl/Tk and later included wi

Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?

2009-03-17 Thread Chris Fuller
This is a super book for beginners who are new to GUI programming. Tkinter is easy to use, and comes included with Python. Serious programmers will probably want something faster, better looking, and with nicer features, but they can be tricky to figure out and install. I still prefer Tkinte

Re: [Tutor] Gtk time control and Glade

2009-03-17 Thread Chris Fuller
Make your own. You can have empty containers in glade that you fill in at runtime, or you could create the interface in glade, perhaps a couple of ComboBoxes. I would leave an empty container and create a reusable widget descended from gtk.HBox that implements validation or anything else that

Re: [Tutor] wxPython vs PyQt

2009-03-04 Thread Chris Fuller
There is a not-free GUI builder, wxDesigner, that isn't too bad (except for costing money). http://www.roebling.de The GLADE GUI builder for Gtk is very nice, however. http://www.pygtk.org/ For windows: http://gladewin32.sourceforge.net/ Cheers ___

Re: [Tutor] Difference in minutes between two time stamps

2009-03-02 Thread Chris Fuller
Use time.strptime() to parse them into seconds since the start of epoch, and then an ordinary numeric subtraction will work. Cheers On Monday 02 March 2009 19:45, Judith Flores wrote: > Hello, > >I can't seem to figure out the syntax to calculate the difference in > minutes between two time

Re: [Tutor] Converting "HH:MM:SS" to datetime

2009-03-01 Thread Chris Fuller
On Sunday 01 March 2009 12:04, Wayne Watson wrote: > Ok, how do I do what's mentioned in Subject? There's an inverse to the strftime() function, strptime(), also in the time module, that will do this. Cheers ___ Tutor maillist - Tutor@python.org htt

Re: [Tutor] File locking: cross platform?

2009-02-20 Thread Chris Fuller
There's a recipe in the Python Cookbook that addresses this: http://code.activestate.com/recipes/65203/ There are probably others floating around, too. Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Newton–Raphson's method

2009-02-16 Thread Chris Fuller
You should look into Numpy or ScientificPython. http://numpy.scipy.org http://dirac.cnrs-orleans.fr/plone/software/scientificpython Also, the main Python Wiki has a page devoted to numeric/scientific topics: http://wiki.python.org/moin/NumericAndScientific Cheers On Monday 16 February 2009 12:3

Re: [Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread Chris Fuller
On Monday 19 January 2009 12:05, Steve Willoughby wrote: > I have a game I'm porting to Python which is currently written > using TCL/Tk. Now it would be fairly easy to make it work in > Python with Tkinter, of course, since the way the GUI would be > organized and implemented would be essentially

Re: [Tutor] cube root

2009-01-19 Thread Chris Fuller
On Monday 19 January 2009 18:56, col speed wrote: > Wow! I seem to have caused a great deal of comments! > I actually am looking to see if a number is a "perfect cube". I will try > out all the suggestions. > Thanks a lot. > Colin The reliable way to do this is to store a list of cubes. If the nu

Re: [Tutor] Translating FORTRAN (77?) to Python?

2009-01-16 Thread Chris Fuller
On Friday 16 January 2009 10:40, Wayne Watson wrote: > I may have a need down the line to convert a large number of lines of > FORTRAN code to Python. Is there a good translator available to do this? In > the past, I've found some for translating Pascal to C, and possibly others. There is a Fotra

Re: [Tutor] Python GIL

2008-11-25 Thread Chris Fuller
Python interpreters running in separate processes have no affect on each other. This is the easiest way to get around the limitations of the GIL. The GIL generally has limited effect on multithreaded applications on a single-core machine. It can be a serious bottleneck on multicore machines,

Re: [Tutor] Creating a single .exe file without py2exe and pyinstaller

2008-10-19 Thread Chris Fuller
The freeze utillity, http://wiki.python.org/moin/Freeze, will do what you want, on unixlikes, at least. It has its own set of caveats, of course. You need a C compiler, and preferably the same one that was used to compile the Python interpreter. I'm not sure if it works at all on Windoze. C

Re: [Tutor] How to clear the screen

2008-10-19 Thread Chris Fuller
There are a couple of approaches here. You could use a screen control library like slang or curses (curses is in the standard library), but that is usually overkill if you aren't creating a moderately complex interface. If you just want to clear the screen, printing the control sequence ESC[2

Re: [Tutor] Pyserial and general python serial help

2008-10-09 Thread Chris Fuller
Are you reading everything in the buffer? How much data is sent every 10ms? At 9600/8/N/1, the throughput is 960 byes a second, so if there's more than 9 bytes, something will give. Similarly, at 115200 baud, the limit is 115 bytes. Some general advice: don't try to sync your program to the 10m

Re: [Tutor] Exiting a PyGTK main loop

2008-09-20 Thread Chris Fuller
Defer the quit until the mainloop is running again. something like self.connect('event-after', gtk.main_quit) Cheers On Friday 19 September 2008 17:16, Bart Cramer wrote: > Dear all, > > I am a bit stuck in a small project, trying to quit a PyGTK program. > Here are some relevant snippets: > >

Re: [Tutor] Shell scripting

2008-09-17 Thread Chris Fuller
Here's a trivial example using backquotes. The tricky part is getting bash to use them in conditionals, variable assignments, and such. 0 % cat > /tmp/fie.py print "Fie!" [ctrl-d] 0 % cat > /tmp/echo.sh echo `python /tmp/fie.py` [ctrl-d] 0 % sh /tmp/echo.sh Fie! 0 % Cheers On Wednesday 17 Sep

Re: [Tutor] Shell scripting

2008-09-17 Thread Chris Fuller
If you want the return code, there are at least two ways to do it. My zsh shell is configured to print the last return code in the prompt: 0 % python Python 2.4.4 (#2, Apr 15 2008, 23:43:20) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "lice

Re: [Tutor] Simple physics simulations)

2008-09-14 Thread Chris Fuller
You could also try out PyGeo, which is based on VisualPython. You could also use a geometry application like Kig, which has Python scripting support. http://pygeo.sourceforge.net/ http://edu.kde.org/kig/ Cheers On Sunday 14 September 2008 02:46, Jim Morcombe wrote: > I want to write a program

Re: [Tutor] Need help with Factorial algorithm using Python

2008-09-04 Thread Chris Fuller
I spent the day mulling over this problem, and then implemented my solution when I got home. This is for the easier problem of 7**8 zeros: On my linux box, running something around 2 GHz, my script runs for about two minutes and the answer is 23059225. You can verify your code to that. I ch

Re: [Tutor] Fwd: Need help with Factorial algorithm using Python

2008-09-04 Thread Chris Fuller
The point of a lot of these challenges is to be smart with your math as well as your code. A brute force approach isn't going to work very well, especially in this case. An integer with 7^20 trailing zeros isn't even going to fit in your RAM. An observation: every trailing zero implies a fac

  1   2   >