2,646 Posted Topics

Member Avatar for EAnder

One way to learn how to produce python byte code without python is to look in python's source code. See how the compile function is implemented in C, and it should give you a clue. Also I suppose that if you want to do the same from java, you should …

Member Avatar for EAnder
0
194
Member Avatar for mahela007

It's because when python reads a file, it has a position in the file and it reads from this position. After the call to open, the position is at the beginning of the file, but after readlines(), the position is at the end of the file. You could do this …

Member Avatar for mahela007
0
104
Member Avatar for MaxManus

Here is my output on scilab, which is similar to matlab [code] -->V=[1,2,3,4]; -->V V = 1. 2. 3. 4. -->V(5)=10; -->V V = 1. 2. 3. 4. 10. [/code] I found the idea here [url]http://www.spas.cnrs-gif.fr/ScilabPasapas-Ch17Sc02.html#c[/url]

Member Avatar for MaxManus
0
174
Member Avatar for blair.mayston
Member Avatar for blair.mayston
0
97
Member Avatar for digiPixel

Did you read this documentation [url]http://peak.telecommunity.com/DevCenter/EggFormats[/url] ? It seems that you need an EGG-INFO directory. I don't create python eggs, so I can't help you much, but I think reading this is the starting point. If you manage creating your egg, please post the key tricks here :)

Member Avatar for digiPixel
0
490
Member Avatar for akshay.sulakhe

There is also a killer search form at the top of this page, you can type 'python gui" and hit the "Search Site" button. There are many threads with this same question in the python forum.

Member Avatar for scru
0
129
Member Avatar for pythononmac

Perhaps you should check this link [url]http://drj11.wordpress.com/2007/05/14/python-how-is-sysstdoutencoding-chosen/[/url] and change the environment variable LC_CTYPE (you should also check if you can change it in your program, using [icode]os.environ[/icode]). I can't test your problem here, because I'm having a french configuration, so the é prints well. By the way, if this is …

Member Avatar for pythononmac
0
684
Member Avatar for leothe3

I posted recently a piece of code where I read the output of a subprocess using a non blocking socket instead of a pipe (linux only, but should work on cygwin). Perhaps you could try this technique [url]http://www.daniweb.com/forums/post777876-19.html[/url]. There is also a nice link, which I posted in the same …

Member Avatar for leothe3
0
1K
Member Avatar for katamole

Well, 1) [icode]list[/icode] is the name of a standard type in python (the type of list objects). A type is just a particular kind of object. 2) Since [icode]list[/icode] is a standard name, it should be avoided as the name of a variable (it's not an error, but it's a …

Member Avatar for MK12
0
168
Member Avatar for breatheasier

May be this will work [code=python] try: range = xrange except NameError: pass def filenames(): for i in range(1, 1001): yield "output%d" % (i * 10000) def average_list(): result = [0.0] * 101 cntfiles = 0 for name in filenames(): cntfiles += 1 file_in = open(name) for index, line in …

Member Avatar for Gribouillis
0
152
Member Avatar for Stefano Mtangoo

What's the point in writing your own chat program anyway ? What will it have that existing great chat programs don't have ?

Member Avatar for lllllIllIlllI
0
174
Member Avatar for katamole

I was more successful with a slightly modified version. I modified the query string. Also, it's a good habit to always use strings prefixed by 'r' when you pass a literal string to re.compile. [code=python] #format the raw_input string for searching raw_string = re.compile(r' ') #search for a space in …

Member Avatar for katamole
0
678
Member Avatar for Norbert X

I have a solution which allows you to use a persistent dictionary between different excecutions of your program, using the with statement (python >= 2.5). Here is an exemple program: [code=python] from __future__ import with_statement from persistent import PersistentDict def main(pdict): if not 'x' in pdict: pdict['x'] = 0 pdict['x'] …

Member Avatar for leegeorg07
0
139
Member Avatar for drone626

I don't think numpy supports arbitrary precision computations, so your determinant was probably computed using floating numbers and you have a round off error in the end. There are libraries for arbitrary precision in python, but they usually don't have a determinant function included.

Member Avatar for Gribouillis
0
106
Member Avatar for g_e_young

I'd suggest [code=python] file_in = open("data/%s.txt" % data) file_list = [] for line in file_in: item = line.split(",")[5] file_list.append(item) [/code] oops, somebody gave the solution before I did :)

Member Avatar for g_e_young
0
128
Member Avatar for toadzky

[icode].{100}[/icode] matches 100 non newline characters, unless you put [icode]re.DOTALL[/icode]. Also I don't understand your replacement string. I think the 0 matches found mean that none of your lines is 100 characters long. You could print a report of the lengths of the lines in your file like this [code=python] …

Member Avatar for scru
0
158
Member Avatar for vjp08

You can use the subprocess module [code=python] import subprocess child = subprocess.Popen("myprog.py") [/code] see the documentation of this module. There are other ways to call your program; [code=python] child = subprocess.Popen("python myprog.py", shell=True) [/code] for example.

Member Avatar for vjp08
0
177
Member Avatar for leegeorg07

if you add a line [icode]print(item)[/icode] before your line [icode]data = urllib.urlopen(item)[/icode] you might see why urlopen can't open the url.

Member Avatar for leegeorg07
0
126
Member Avatar for madurai07

It could be an indentation problem, but since you don't wrap your code in code tags as paulthom says above, it's difficult to see what's wrong.

Member Avatar for madurai07
0
136
Member Avatar for gabec94

Instead of 7 variables row1, row2, etc, you could have one variable rows, which is an array of rows [code=python] rows = [ [' ' for i in range(7)] for j in range(7)] template = " %s |" * 7 def make_board(): for i in range(6, -1, -1): print(("%d |" …

Member Avatar for lllllIllIlllI
0
138
Member Avatar for scru

Here is my console output on Mandriva linux 2009: [code=python] Python 3.0 (r30:67503, Dec 9 2008, 13:32:06) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> [/code] I think that all library module names have been converted to lowercase in python 3.0.

Member Avatar for Ene Uran
-1
270
Member Avatar for SoulMazer

Your problem is called "input validation". Each time that you ask some input to the user, there is a high probability that the user enters unexpected input and your program must handle this (= validate input). Here you could use a test like this [code=python] answer = raw_input("> ") answer …

Member Avatar for SoulMazer
0
102
Member Avatar for wotthe2000

You can change addbook like this [code=python] def addbook(ISBN, author, title, stock): if ISBN in booklist: booklist[ISBN][2] += stock else: booklist[ISBN] = [author, title, stock] [/code]

Member Avatar for Ghostenshell
0
153
Member Avatar for thehivetyrant
Member Avatar for thehivetyrant
0
493
Member Avatar for revenge2

Q2 for an expression like text[start: stop: step], if text is a string, it will return a string whith the characters text[start], text[start+step], text[start+2*step], etc, as long as start + k*step < stop if step is > 0 and start + k*step > stop if step < 0. When start …

Member Avatar for Ene Uran
0
125
Member Avatar for EAnder

I quote the python 3.0 documentation: "If the subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread." So I think you should start your class like this [code=python] class UpdateLabels(Thread):#activates in main...did not work? def __init__(self): Thread.__init__(self) …

Member Avatar for Ene Uran
0
118
Member Avatar for adam291086

It's because the builtin function open can only open a file in your filesystem and not an url. If you want to rewrite a file in your website, you should first write a file in your local file system and then use ftp or some other protocol to copy the …

Member Avatar for Gribouillis
0
121
Member Avatar for TheNational22

This seems to be a fix in the C++ source code of wxWidget. If you want to use this fix, you must recompile wxWidget yourself. This is not normally a solution for the end user. If this link really describes your problem, you will have to wait that the fix …

Member Avatar for TheNational22
0
96
Member Avatar for adam291086

You changed the indentation of [icode]for subelement in element:[/icode].

Member Avatar for adam291086
0
105
Member Avatar for tzushky

I can't resist giving you a sexy solution [code=python] import sys import webbrowser import cgitb def output_exc(): f = open("exception.html", "w") f.write(cgitb.html(sys.exc_info())) f.close() webbrowser.get("firefox").open("exception.html") # or webbrowser.open("exception.html") if you don't use firefox class incomplete: def __init__(self): self.first = 1 self.second = 2 i = incomplete() try: print i.first print i.second …

Member Avatar for Gribouillis
0
226
Member Avatar for codedhands

[QUOTE=paulthom12345;782620] [code=python] file_in = open("myfile.txt", "r") allfile = '' for line in file_in: allfile += line [/code] [/QUOTE] why don't you just use [icode]allfile=file_in.read()[/icode] ?

Member Avatar for lllllIllIlllI
0
98
Member Avatar for Gribouillis

What do you think would be the best way to write this structure [code=python] if testA: actionA() if testB: actionB() if textC: actionC() else: actionDefault() else: actionDefault() else: actionDefault() [/code] if I want to write only one call to actionDefault() ?

Member Avatar for Gribouillis
0
139
Member Avatar for dineshjaju

try this [code=python] #Python code: import csv # first we need import necessary lib:csv file=open("dinesh.csv", "w") #prepare a csv file for our example testWriter = csv.writer(file, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) testWriter.writerow(['Test'] * 5 + ['Wow']) file.close() [/code]

Member Avatar for jice
0
104
Member Avatar for tzushky

LINUX only possible solution: On linux, there is the standard module [inlinecode]commands[/inlinecode] so you could write [code=python] from commands import getstatusoutput cmd = "myAppli arg1 arg2 arg3" status, output = getstatusoutput(cmd) if not status: ... # process output else: raise Exception("command '%s' failed with exist status '%s'" % (cmd, status)) …

Member Avatar for Gribouillis
0
14K
Member Avatar for red999

I agree with Sillyboy, sum is not a syntax, it's a function which applies to a sequence. Here I think that the expression that you put in the sum is the value of your investment, so you can simply drop the sum. However I think your program is confusing because …

Member Avatar for paddy3118
0
187
Member Avatar for Stefano Mtangoo

There should be something here [icode]CHAR, ? CHAR)" (t_name, t_date[/icode] between the string and the opening parenthesis :)

Member Avatar for Stefano Mtangoo
0
2K
Member Avatar for Ghostenshell

Here is another one (faster ?) [code=python] #!/usr/bin/env python import re def main(): regexes = [ re.compile(x) for x in (r"[^A-Z]+", r"[^a-z]+", r"[^0-9]+", r"[^\ ]+")] filename = "test.txt" content = open(filename).read() counts = [len(s) for s in (r.sub("", content) for r in regexes)] print("""There are %d uppercase letters %d lowercase …

Member Avatar for Stefano Mtangoo
0
972
Member Avatar for Radly

There's a built-in [icode]reload[/icode] function. It takes a module object as it's argument, so you can use [icode]reload(sys.modules["kitten"])[/icode] or [code=python] import kittens reload(kittens) [/code] It works only for python modules, not for shared libraries.

Member Avatar for Radly
0
88
Member Avatar for wotthe2000

Here is how you could write this [code=python] def create_message(message, msgstr): if msgstr[0:3].upper() == 'CMD': return message(msgstr) elif msgstr[0:3].upper() == 'RSP': return message(msgstr) elif msgstr[0:3].upper() == 'IND': return message(msgstr) elif msgstr[0:3].upper() not in 'CMDRSPIND': print "Miscellaneous message has been found with details", msgstr else: pass class message(object): def __init__(self, msgstr): …

Member Avatar for wotthe2000
0
96
Member Avatar for noamjob

I suggest this if you want to see the pdf file [code=python] import webbrowser webbrowser.open("http://fetac.ie/MODULES/D20120.pdf") [/code]

Member Avatar for Stefano Mtangoo
0
6K
Member Avatar for Gribouillis

In python, a "function object", that is to say an object which can be called as a function, is simply an instance of a class which has a [icode]__call__[/icode] method. An example is [code=python] class FuncObj(object): def __call__(self, *args): print("args were %s." % str(args)) func = FuncObj() func(1,2,3) # output …

Member Avatar for Gribouillis
0
184
Member Avatar for marcux

In fact, if you issue the command [icode]pydoc -w pkg1.pkg2[/icode], it will generate your [icode]pkg1.pkg2.html[/icode]. After [icode]pydoc -w[/icode], you must not put the path of a file or a directory, but the module path of a python module as if you were importing it in python with [icode]import pkg1.pkg2[/icode]. Now …

Member Avatar for Gribouillis
0
2K
Member Avatar for Stefano Mtangoo

I don't think you really need a tutorial. Start like this [code=python] >>> from wx.lib.mixins import listctrl >>> help(listctrl) [/code] Note that the help for the class [icode]TextEditMixin[/icode] shows you how to use the mixin class. You should try each mixin class in the same way, and then try to …

Member Avatar for Stefano Mtangoo
0
96
Member Avatar for Luckymeera

Your cars are initialized with a speed of 0, 0. You should call their [icode]set_speed[/icode] method to define another value. If you don't start the cars, they won't move !

Member Avatar for Luckymeera
0
112
Member Avatar for acoxia

One day we should write the ultimate hangman program in this forum. It looks like a recurrent theme in CS classes :)

Member Avatar for ashutosa
0
170
Member Avatar for mn_kthompson

I think you should copy the list like this [code=python] class MSULinkExtractor(htmllib.HTMLParser): ... def get_links(self): print '\tMSULinkExtractor.get_links has been called' return list(self.links) ... [/code]

Member Avatar for Gribouillis
0
299
Member Avatar for kiddo39

You could try [icode]print(set(img_I))[/icode] to see all the colors contained in your image.

Member Avatar for kiddo39
0
343
Member Avatar for lllllIllIlllI

The pydoc module (used by the function 'help') finds all definitions in a module and produces text or html documentation. I read that it does this by importing the module first and then using objects introspection. If you look at the code of [icode]pydoc.py[/icode] in your standard library, you should …

Member Avatar for lllllIllIlllI
0
127
Member Avatar for elvenstruggle

[QUOTE=jlm699;772442]Try out [URL="http://code.activestate.com/recipes/148061/"]this guy[/URL][/QUOTE] One of the comment of this snippet says that there is a standard module [icode]textwrap[/icode]. I think it will do a better job.

Member Avatar for Gribouillis
0
141
Member Avatar for nitu_thakkar

Python is a high level object oriented programming language created at the beginning of the 90's bu Guido Van Rossum. Python allows for fast software development, which is the main reason of its success. The official site of the language is [url]www.python.org[/url].

Member Avatar for Stefano Mtangoo
-1
355

The End.