2,646 Posted Topics
Re: Can you post the whole traceback ? | |
Re: You could also install a ssh server on the server machine and access directories with module paramiko (make sure the ssh server is securely configured). In windows, you can install [b]copssh[/b] for example. (note that when I installed copssh in my windows XP, I had a missing dll which I … | |
Re: You can look in the source code of timemodule.c in the python source. In linux, this is done by calling select() with NULL arguments. | |
Re: [QUOTE=HuXiaoxiang;1585513]Hi all, Forgive my pool English first... I'm learning Python recently. But I met with a problem yesterday and I have liitle experience in solving this kind of problems. Here are the code in Python Shell: [CODE]>>> "HuXiaoxiang\\0Nanjing University\03 Years.".replace("\0"," ") 'HuXiaoxiang\\0Nanjing University\x03 Years.' >>> "HuXiaoxiang \0Nanjing University\03 years.".replace("\0"," ") … | |
Re: Using the [icode]key[/icode] argument of sorted() or list.sort(), you can sort a list of items according to a score function. The score of an item could be its price, name, age, mark, length, distance to a point, etc depending on what the items are. [code=python] from functools import partial def … | |
Re: Didn't you forget the argument [icode]convertEntities=BeautifulSoup.HTML_ENTITIES[/icode] in BeautifulSoup() ? | |
Re: I added a small sleep() and it worked ! why ? I DONT KNOW :) [code=python] import pexpect import sys import code from time import sleep child = pexpect.spawn('gdb', logfile = sys.stdout) sleep(0.3) try: child.expect(pexpect.EOF,timeout=0) except Exception, e: print child.before code.interact(local=globals()) """ my output --> GNU gdb (GDB) 7.1-1mdv2010.1 (Mandriva … | |
Re: You can add this method to handle accented characters [code=python] def handle_charref(self, name): if self.this_is_the_tag and not self.end_of_city: print "charref", repr(name) self.this_city += unichr(int(name)) [/code] There is still a problem with your web page. HTMLparser exits with an error (after finding the cities). You may consider using a parser for … | |
Re: I think there are many ways of saving the user settings. If your aplication is named MyGreatApp, the idea is to create a folder named MyGreatApp which contains your configuration files (in text or xml formats, or split in several files in several subdirectories). The location of the folder MyGreatApp … | |
Re: Perhaps you could compress the text first to reduce its size [code=python] import zlib text = open("file_to_be_encrypted.txt").read() data = zlib.compress(text) # normaly much shorter than text # ... encrypt data with your AES code # text can be retrieved with zlib.decompress(data) [/code] This technique won't help if your data is … | |
Re: [QUOTE=tonyjv;1582310]I do not see what connection your question has with Python.[/QUOTE] Google's first result tells you a possible connection with python, and also a probable solution [url]http://stackoverflow.com/questions/2272786/python-issueunable-to-find-vcvarsall-bat[/url] :) Apparently, it can happen when you're installing a package that needs to compile C or C++. | |
Re: Google gives many answers. See this one from Alex on linux. Alex usually writes good python articles [url]http://www.alexonlinux.com/how-to-send-sms-message-with-python[/url] . | |
Re: The first problem is that you are using attributes starting with double underscores. Double underscores are used by the interpreter to simulate "private" attributes (which don't really exist in the language). So if you set an attribute [icode]__dic[/icode], the instance will actually have an attribute [icode]_Test__dic[/icode] instead of [icode]__dic[/icode]. The … | |
Re: There are 2 slightly different things that you might want to do [LIST] [*]execute a script xxx.py from your main program. This can be done with [icode]exec open("xxx.py").read()[/icode] [*]import xxx.py as a module, which is done with [icode]import xxx[/icode] or [icode]mod = __import__("xxx")[/icode] [/LIST] If you import the module, the … | |
Re: Perhaps this post can help you [url]http://www.daniweb.com/software-development/python/threads/351458/1493468#post1493468[/url]. Also, read this doc page [url]http://docs.python.org/install/index.html[/url] | |
Re: I would say it's [icode]a[row][column][/icode]. So, use 'row' and 'col' instead of x and y. | |
Re: It works with [code=python] def call_back(self, event): self.zones = self.Lb1.curselection() assert len(self.zones) == 1 z = self.zones[0] if z == '0': self.make_Red() elif z == '1': self.make_Green() elif z == '2': self.make_Blue() [/code] Also, configure your editor to indent with 4 spaces, it will be easier to help. | |
Re: I think it is best to avoid the use of the built in function [icode]callable[/icode], because Guido van Rossum thought it was a mistake in the python language (perhaps because of similar questions, what does callable actually means). That's why it was removed in python 3. I like the [icode]hasattr(x, … | |
Re: You can use string formating operations [code=python] ["ma%d" % n for n in range(2, 5)] [/code] | |
Re: [QUOTE=novice20;1560533]Hi, I want to do something like this: I have two lists: list1 = range(6) list2 = range(10,15) i want a dictionary like this: adict ={0:10, 1:11, 2:12, 3:13, 4:14, 5:15 } I did the following: [CODE]list1 = range(6) list2 = range(10,15) adict = dict(zip(list1,list2))[/CODE] i get : [B]TypeError: list … | |
Re: There are different libraries for big floating numbers in python, most of them based on the gnu multiprecision library see [url=http://packages.python.org/bigfloat/]bigfloat[/url] and [url=http://gmpy.sourceforge.net/]gmpy[/url] and also [url=http://calcrpnpy.sourceforge.net/clnum.html]clnum[/url]. | |
Re: [QUOTE=hisan;1556631]Hello All, Ii want to know how can i check whether the response from the server is inJSON format or XML format . Please let me know how to do this,[/QUOTE] The first idea is try and parse it with json.loads(), if it raises ValueError, it may well be xml … | |
Re: [QUOTE=griswolf;1559001]you want some variation on code like this[CODE]gracefulStart() # create circle etc while True: # display the circle # do some work; pause; etc if readyToStop(): break # adjust the location of the circle gracefulEnd() [/CODE][/QUOTE] Also possibly create a second moving circle to simulate reapearance at the other side … | |
Re: Perhaps you should set the file type association as described here [url]http://www.techrepublic.com/article/windows-vistas-default-programs-tool-more-than-what-youd-expect/6186021[/url] . | |
I just started a new small python project on google code which goal is to easily create clickable graphs on a GKT+ goocanvas. The initial idea comes from this code snippet [url]http://www.daniweb.com/software-development/python/code/323792[/url] . I want to do about the same, but instead of simply drawing the graph, I want to … | |
Re: Here is a much faster version using numpy [code=python] from numpy.fft import fft, ifft import numpy as np def func(f, d): a = np.zeros((d*f,)) a[:f] = np.ones((f,)) x = ifft(fft(a) ** d) return [int(z) for z in x + .49][:d*(f-1) + 1] def test_it(f, d): sums = find_sums(d, f) table … | |
Re: [QUOTE=Layra;1558054]I went and looked up the tksnack from the website posted and the latest version is for Python 2.2. Considering Python latest is 3.1, will this library still work? I'm very interested in this for my final project and would prefer to use this or something similar / more up … | |
Re: Perhaps you should start with pytesser [url]http://code.google.com/p/pytesser/[/url] which binds python to the tesseract OCR engine. Tesseract has a good reputation (although I never used it myself). | |
Re: If each entry contains 8 bits of data, you may consider using the array module instead of a list. Otherwise the code that you wrote above doesn't produce list index out of range error. This error does not occur randomly, so your program must have changed the size of the … | |
Re: [QUOTE=tonyjv;1556247]If you would multiply all values by constant, say 1000000, and divide solution accordingly, maybe it could work out to transform the problem to integer realm.[/QUOTE] This is not a good idea. LP problems are much easier to solve with real numbers than with integers, so yes I think pulp … | |
Re: This code is ugly, [b]use lists[/b], eg [code=python] numglobals.frame[10] = Mat[9](None,-1,"") if self.combo_box[4].GetValue() == "1": ... [/code] | |
Re: Using Counter looks good, but it will work only with python >= 2.7. The problem with your question is that there is no python code. Hint: start with a program which prints each list item on a different line. | |
Re: I don't use Mac OSX, nor Activestate python but, you should be able to see where is your wx package by running [code=python] >>> import wx >>> wx.__file__ '/usr/lib64/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/__init__.py' [/code] This should give you the path to the 'site-packages' directory (for me in linux, it is /usr/lib64/python2.6/site-packages). Now, if you … | |
Re: [QUOTE=HiHe;1552810]I was exploring random art and modified this nice example from vegaseat: [code]# random circles in Tkinter # a left mouse double click will idle action for 5 seconds # modified vegaseat's code from: # http://www.daniweb.com/software-development/python/code/216626 import random as rn import time try: # Python2 import Tkinter as tk except … | |
Re: There are different ways to do it. Here is one [code=python] >>> for score, name in nameScore: ... print "{0}, {1}".format(score, name) ... 13, Matthew 6, Luke 3, John 3, john [/code] Also, use code tags when you post python code. See here [url]http://www.daniweb.com/forums/announcement.php?f=8&announcementid=3[/url] | |
Re: Python's importer does not understand .tar.gz files. You should uncompress the files with 7zip and install the modules properly. Alternately, you can extract them with python [code=python] import tarfile tar = tarfile.open(mode= "r:gz", fileobj = open("path_to_tgz_file", "rb")) tar.extractall("path_to_folder_where_to_extract") # for example "." [/code] | |
Re: [QUOTE=jkrueger;1550589]In Linux all terminals use commands that I'm very comfortable with, that is how I chose Cygwins terminals. With CMD I have to be in the python directory to run python, with xrvt I can be any where. The issue really is running a script with colorama using xrvt $ … | |
Re: The most obvious solution is to define your own classes of mutable lists or dicts. Such classes exist in some modules. For exemple the ZODB module implements persistent lists and dicts which catch all changes done to the instances (basically, it sets a boolean telling the system that the content … | |
Re: You are using a variable row_num which was only defined in the function row() and does not exist outside this function. It's better to write separate functions with return value to get user input, like this [code=python] # -*-coding: utf8-*- #created by Jaron Graveley #April 26th, 2011 #This program completes … | |
Re: See [icode]itertools.product("daniweb", repeat=3)[/icode]. | |
Re: [icode]sys.argv[/icode] is the list of command line arguments that were passed to your python program. QApplication() may use command line arguments, as described here for example [url]http://doc.trolltech.com/latest/qapplication.html#QApplication[/url] (this is not the python version, but the same principle applies). Here is a example program [code=python] # myprog.py import sys print(sys.argv) [/code] … | |
Re: You can use [code=python] name, number = line.strip().split() [/code] | |
Re: If you only want to add some random noise to your data, you could add a normal random sample with a small standard deviation and clip the result in the interval [-1.0, 1.0] like this [code=python] sigma = 0.1 a = numpy.clip(X + sigma * randn(100, 20), -1.0, 1.0) [/code] … | |
Re: [QUOTE=HiHe;1542585]This works with Python 2.7 [code]class B: def __init__(self, arg): print(arg) class C(B): def __init___(self, arg): super(C, self).__init__(arg) c = C('abc') # abc [/code]Here super() gives a TypeError: must be type, not classobj [code]from math import pi class Circle: """with Python3 object is inherited automagically""" def __init__(self, r): self.r = … | |
Re: Don't waste time writing and editor or an IDE! Don't reinvent the wheel! Go to the [url=http://en.wikipedia.org/wiki/List_of_algorithms]wikipedia list of algorithms[/url], which points to virtually hundreds or thousands of clever algorithms, and implement a few of them in python. | |
Re: The [icode]with[/icode] statement applies to instances having 2 methods: "__enter__" and "__exit__". When the with statement is encountered, the instance's __enter__ method is called and its return value is used for the 'as' part of the statement. When the block exits, the instance's __exit__ method is called to perform cleanup … | |
Re: You defined fru only if a test suceeded. What you should do is replace lines 12-18 with [code=python] fru = None # give an initial dummy value to fru for pa in pa_list: try: nodevalue = pa.attributes.getNamedItem('name').nodeValue print "nodevalue: %s" % str(nodevalue) # for debugging purposes if nodevalue == 'apple': … | |
Re: You can generate pairs of items to compare with a function [code=python] def pairs(alist): for i, x in enumerate(alist): for y in alist[i+1:]: yield x, y L = list("abcdefgh") print "initial list: ", L for u, v in pairs(L): print (u, v), print [/code] Otheriwse, in your code, the double … | |
Re: I suggest [code=python] re.search(r'0x0*[1-9a-f][0-9a-f]*', ...) [/code] |
The End.