94 Posted Topics
Re: Hi jamshid, In the first example, keep in mind that when you say "7/3" in Python, you are telling it to divide the integer 7 by the integer 3. Python, like many programming languages, makes a distinction between integers and real numbers, so that any operation carried out on integers … | |
Re: Hi msaenz, I have used BioPython before and I am familiar with the format of FASTA files, but I'm not sure that I understand the problem. Is it that you want to create an indexed database of FASTA files for searching, but you keep getting key collisions because you're using … | |
Re: Hi gbs, It is possible that (a) there are two versions of ps2pdf installed on your system, and the apache user uses one and the root user uses the other, or the more likely case, (b) something in the root environment which is necessary for ps2pdf's proper function is missing … | |
Re: Hi whoru, You can load pickled data into an object of your choosing by saying:[CODE]import cPickle f = "somefilename.dat" a = cPickle.load(open(f, "r")) # Proceed to do things with object a[/CODE]vegaseat included a comparable set of instructions at the end of his snippet. | |
Re: Hi butterflyTee, Please check your PM inbox. To get the numbers to line up, you are going to need to use a formatting modifier to your print statement. Try something like:[CODE]print str("%3d" %int(chill))+" ",[/CODE]instead of the print statement you have in your nested for-loop. This should space the numbers properly. | |
Re: Hi rabidpanda, It could be a classpath issue. Is Hangman.java in the same directory as your other two files? If not, try setting the classpath explicitly using the -classpath command-line option to javac. | |
Re: Hi a1eio, So, you want this window to have an "always on top" quality to it, like you can do with Winamp, right? And you want the window to be not only on top of all the other Tkinter/WxPython/whatever windows, but on top of every running app window currently on … | |
Re: Hi bumsfeld, Well, let's think about this. Suppose that we want to create a variable 'count' that records the number of times a function 'myfunc()' is called. If the variable's scope is limited to the function itself, it will disappear off the runtime stack when the function call is completed. … | |
Hi all, I'm writing a simple MIDI player (which I might eventually turn into a editor, if I feel ambitious). To that end, I've been futzing around with the pygame.mixer and pygame.mixer.music modules. I can get MIDI files to play, but I would also like to be able to grab … | |
Re: Hi python_dev, I don't use wxPython to do GUI stuff, but I think I can see what the problem is, and how to fix it. You can't use dv3 inside listDir() to figure out which button was just pressed. Rather, you need to get that button's ID by going through … | |
Re: Hi shafter111, If you are dividing an integer by some other number and you want the quotient to be a float, you need to cast the integer to a float. In other words:[CODE]a, b = 8, 3 temp = ((a-b)/a)*100 # Gives you zero[/CODE] While:[CODE]a, b = 8, 3 temp … | |
Re: You are using Apache to serve content, right? If that's the case, the Mod_python module (an Apache module, not a Python module) provides PSP (Python Server Pages) functionality - just what you'd need to replace your JSPs. You can get more information on this platform by following these links: [URL=http://www.onlamp.com/pub/a/python/2004/02/26/python_server_pages.html]Basic … | |
Re: Hi pythonguy, Hmm. It sounds like AutomationDesk is sending EOF signals to your scripts without being asked. I can't think of a really good way to explore this problem without my own copy of AutomationDesk (I don't have one). It's commercial software, right? You're probably better off emailing the dSPACE … | |
Re: There is. [CODE]import calendar s = calendar.month(2006, 3) print s[/CODE]- gives the same effect. If I am understanding this correctly, the prmonth() method does not return a value - it only prints. If you are dead-set on using prmonth() to get at this data, I think you will need to … | |
Re: Hi butterflyTee, Out of curiosity, which university or school do you attend where the homework assignments need to be written in Python? I have never seen a Python CS curriculum before, and I am interested to see what it looks like. | |
Re: Hi juergenkemeter, You want to set up some kind of GUI window that displays the main hair follicle life cycle image, such that when you click the mouse (or press the space key, or enter some other input) a new layer pops up, with maybe a tinted, transparent shape over … | |
![]() | Re: Hi iamthwee, The problem of classifying image files according to what's inside them falls into the general category of "supervised learning problems." To see how to solve these kinds of problems, let's consider a very simple example: Suppose I give you a thousand images in separate image files. Each image … |
Re: Hi shanenin, Here's one way of doing it:[CODE]import sys, os, time, thread # Keep track of thread PIDs t1, t2 = 0, 0 # The major thread function def f(timeslice): # Set t2 to the PID for this thread global t2 t2 = os.getpid() # Loop, do something after every … | |
Re: If the class only needs to be instantiated once, does it need to be instantiated at all? Why not use static methods? My personal preference is to avoid adding object-orientation that doesn't have to be there - it makes everything seem cleaner, somehow. This also takes care of the constructor … | |
Re: Mmm. That was a good article, jwenting! I especially liked the poem. This article doesn't refer to Java IDEs, and it isn't specifically about GUI builders, but it is in the same vein: [URL=http://charlespetzold.com/etc/DoesVisualStudioRotTheMind.html]Does Visual Studio Rot the Mind?[/URL] I also use the command line, and emacs is my editor … | |
Re: What you have here is a so-called "singly-linked list" data structure. Basically, a singly-linked list is a collection of Node objects. Each Node object has two fields: a [I]data[/I] field (often a String or integer, though really it could be anything - even another object), and a [I]link[/I] field which … | |
Re: Hi riabear123, Let's take a look at your Lotto.java file and try to figure out what it's doing. First, you import the Random class from java.util, because you need some way of generating random numbers. Then you set up the object-oriented overhead - the class and main method declarations. Then … | |
Re: From the [URL=http://diveintopython.org/getting_to_know_python/dictionaries.html]Dive Into Python[/URL] tutorial: "Dictionaries have no concept of order among elements. It is incorrect to say that the elements are 'out of order'; they are simply unordered. This is an important distinction which will annoy you when you want to access the elements of a dictionary in … | |
Hi all, I just added a clustering module to the code snippets. There are classes for modeling points and clusters of points, as well as two point-clustering functions - one is an implementation of the k-means algorithm, which I believe I posted earlier this year, and the other is an … | |
Re: Hi bumsfeld, Well, the naive solution might be something like this:[CODE]a, b = dict(), dict() a["a_one"], a["a_two"], a["a_three"] = "a1", "a2", "a3" b["b_one"], b["b_two"], b["b_three"] = "b1", "b2", "b3" for k in a.keys(): if b.has_key(k): continue else: b[k] = a[k] print b[/CODE]After the loop terminates, b has all of a's … | |
Re: Hi Skyline_GTR, It looks like the second y-coordinate for each of your if-elifs is off by 80, because you told the turtle to walk 40 steps in the wrong direction. In other words, change your polygon() function to look like this:[CODE]def polygon(sides,length): for step in range(sides): print turtle.position() turtle.forward(length) turtle.left(360/sides)[/CODE]All … | |
Re: Hmm. Here's one way around it, using exec() instead of getattr(): [CODE]import sys # For our example, let's use random.sample() as the desired attribute # This function takes as input a list and an integer n and returns a # random, non-redundant selection of n elements from the list modname … | |
Re: To get two Python functions running concurrently, you're going to need to look at Python's threading modules. There is a good site with example code [URL=http://linuxgazette.net/107/pai.html]here[/URL]. As for the main question, well, you could always exec() the second Python program from the first. But please don't do this unless you … | |
Re: It looks like you haven't included all the code you wrote to test this. Were there statements after 'drugi = Person('Mici')'? Statements like, perhaps: [CODE]del drugi del prvi[/CODE] If so, please include them, because the other code worked fine for me. | |
Re: So all you need is a list where each element is the first word on each line in the text file? This is a fairly simple regular expression problem: [CODE]import sys, re # Open the file with read-access f = open("doc/dict.txt", "r") # Read the file text as one big … | |
Here's a cute little encipher/decipher program with a Tkinter GUI I wrote a while back. It's an implementation of a derivative of the Vigenere algorithm; the algorithm is taken from Laurence Smith's [U]Cryptography: The Science of Secret Writing[/U], Amazon link [URL=http://www.amazon.com/exec/obidos/tg/detail/-/048620247X/qid=1125004078/sr=8-1/ref=sr_8_xs_ap_i1_xgl14/102-6170856-3267319?v=glance&s=books&n=507846]here[/URL]. It's a dated book (and the technique itself is … | |
Re: Hi mccarthp, Let me see if I understand this. Windows maintains a variable called errorlevel, which contains the exit code of the most recently executed program, right? And you are trying to read that variable? Hmm. Off the top of my head, we could try: [CODE]import os keys = os.environ.keys() … | |
Re: a1eio, What method are you using to read the file? Are you doing something like this? [CODE]f = open(filename, "r") text = f.read() print text[/CODE]Is the file very large? | |
Re: Hi cleblanc, I need more information about how this program will be used if I am to provide useful information myself. First off, is this program going to be used by people, or is it a mock-up/homework assignment? If it's going to be used by people, it's not necessarily a … | |
Re: Hi xav.vijay, I'm not sure, and I can't check right now because I'm at work and using my XP box, but: Isn't the difference between top and df/ls that programs like df/ls write to STDOUT once and then terminate, while top keeps writing to the terminal window, dynamically updating the … | |
Re: Heh. Nobody understands classes the first time around. When I was learning this stuff in Java, it took me about six months and 10+ OO* programs before I fully grokked what I was doing. Reading up on classes is great, but if you really want to understand them, you have … | |
Re: Hi shanenin, You might want to check out the [URL=http://docs.python.org/lib/module-ConfigParser.html]ConfigParser object[/URL]. I don't use it myself; I wrote my own. I must confess: I'm a little leery of your solution, since it involves executing the contents of a file without making security checks first. What if the file gets hacked? … | |
Re: Hi danizzil14, You'll need to do: [CODE]ansLabel.configure(text='The area of your square is' + \ (float(squareHight.get()) * float(squareWidth.get())))[/CODE] This should work. Why doesn't squareHight.get() work? I'm guessing that squareHight and squareWidth are both StringVars, correct? If that is the case, then squareHight.get() and squareWidth.get() both resolve to [I]string values[/I], and the … | |
Hi all, Here's one that has me stumped. I'm trying to build a system shell with a Tkinter GUI in Python, and I can't figure out what to do with one of the widgets. Here's the program concept: I have two major widgets: a ScrolledText widget and an Entry widget. … | |
Re: Hi Shanenin, Try this: [CODE]from Tkinter import * # -- The application class class TkBasic: # -- Initializes new instances of TkBasic def __init__(self, root): # Change the window geometry root.geometry("300x200+30+30") # Add the window Frame to which all widgets will be bound self.mainframe = Frame(root) self.mainframe.pack() # Add a … | |
Re: I don't know about directories, but picking files is as easy as implementing a TkFileDialog widget in Tkinter. See Fredrik Lundh's generally excellent (though unfinished) Tkinter tutorial at: [url]http://www.pythonware.com/library/tkinter/introduction[/url] The bit you're looking for is in the "Dialogs" chapter under "Data Entry." Tkinter's [I]really[/I] easy to use, BTW. | |
Hi, I'm writing a client program that downloads data from an HTTP server via urllib, like so: [CODE]ufile = urllib.urlopen(urlstring) text = ufile.read() # Do stuff with text[/CODE] Nice and simple. Unfortunately, the server only accepts requests with a session ID embedded inside - and I don't know how to … | |
Re: You know, if you are invoking javac and java from a command (DOS) terminal, you can override the environment classpath on the command line by saying: C:/> javac -classpath c:/blah/blah/blah; and C:/> java -classpath c:/blah/blah/blah; where the "c:/blah/blah/blah;" business is your classpath. If you want to check that [i]your[/i] classpath … | |
Hi, I am a Java programmer dabbling in Python for the first time. Mostly, the transition has been pretty smooth, but this week something stumped me. Please forgive me if the answer to this is completely obvious - I've read van Rossum's tutorial and can't figure it out. I am … |
The End.