2,646 Posted Topics

Member Avatar for Eswarimallur
Member Avatar for yuvalm2

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 …

Member Avatar for richieking
0
120
Member Avatar for techie1991

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.

Member Avatar for techie1991
0
2K
Member Avatar for HuXiaoxiang

[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"," ") …

Member Avatar for HuXiaoxiang
0
253
Member Avatar for jarograv

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 …

Member Avatar for Gribouillis
0
108
Member Avatar for Huakalero

Didn't you forget the argument [icode]convertEntities=BeautifulSoup.HTML_ENTITIES[/icode] in BeautifulSoup() ?

Member Avatar for Huakalero
0
882
Member Avatar for krazykat1010

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 …

Member Avatar for krazykat1010
0
252
Member Avatar for Huakalero

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 …

Member Avatar for Huakalero
0
351
Member Avatar for markfw

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 …

Member Avatar for Gribouillis
0
122
Member Avatar for drak0

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 …

Member Avatar for drak0
0
634
Member Avatar for dustbunny000

[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++.

Member Avatar for Gribouillis
0
251
Member Avatar for mukthyar1255
Member Avatar for mukthyar1255

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] .

Member Avatar for Gribouillis
0
50
Member Avatar for markfw

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 …

Member Avatar for markfw
0
168
Member Avatar for novice20

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 …

Member Avatar for novice20
0
190
Member Avatar for mukthyar1255

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]

Member Avatar for Gribouillis
0
84
Member Avatar for Shane the House

I would say it's [icode]a[row][column][/icode]. So, use 'row' and 'col' instead of x and y.

Member Avatar for vegaseat
0
121
Member Avatar for Behseini

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.

Member Avatar for Lardmeister
0
9K
Member Avatar for Ephexeve

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, …

Member Avatar for TrustyTony
0
277
Member Avatar for rssk

You can use string formating operations [code=python] ["ma%d" % n for n in range(2, 5)] [/code]

Member Avatar for TrustyTony
0
222
Member Avatar for novice20

[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 …

Member Avatar for novice20
0
232
Member Avatar for WolfShield

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].

Member Avatar for WolfShield
0
321
Member Avatar for hisan

[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 …

Member Avatar for sneekula
0
350
Member Avatar for kmilof

[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 …

Member Avatar for predator78
0
226
Member Avatar for WolfShield

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] .

Member Avatar for WolfShield
0
191
Member Avatar for Gribouillis

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 …

Member Avatar for Gribouillis
1
170
Member Avatar for TrustyTony

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 …

Member Avatar for TrustyTony
1
269
Member Avatar for vegaseat

[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 …

Member Avatar for Layra
3
5K
Member Avatar for kenkit

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).

Member Avatar for kenkit
0
88
Member Avatar for novice20

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 …

Member Avatar for novice20
0
521
Member Avatar for Shansal

[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 …

Member Avatar for Gribouillis
0
289
Member Avatar for aplh_ucsc

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]

Member Avatar for Gribouillis
-1
327
Member Avatar for Shansal

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.

Member Avatar for TrustyTony
0
175
Member Avatar for imperialguy

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 …

Member Avatar for imperialguy
0
620
Member Avatar for HiHe

[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 …

Member Avatar for HiHe
0
18K
Member Avatar for laung

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]

Member Avatar for TrustyTony
0
192
Member Avatar for novice20

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]

Member Avatar for snippsat
0
2K
Member Avatar for jkrueger

[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 $ …

Member Avatar for jkrueger
0
373
Member Avatar for ihatehippies

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 …

Member Avatar for ihatehippies
0
229
Member Avatar for jarograv

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 …

Member Avatar for jarograv
0
249
Member Avatar for Krstevski
Member Avatar for Tech B
0
116
Member Avatar for Shift_

[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] …

Member Avatar for Gribouillis
0
125
Member Avatar for Shift_
Member Avatar for Shift_
0
746
Member Avatar for pythonbegin

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] …

Member Avatar for pythonbegin
0
2K
Member Avatar for HiHe

[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 = …

Member Avatar for HiHe
0
281
Member Avatar for Stefano Mtangoo

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.

Member Avatar for lrh9
0
6K
Member Avatar for Joeflims

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 …

Member Avatar for Joeflims
0
138
Member Avatar for SakuraPink

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': …

Member Avatar for SakuraPink
0
4K
Member Avatar for parijat24

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 …

Member Avatar for Gribouillis
0
323
Member Avatar for blacknred

I suggest [code=python] re.search(r'0x0*[1-9a-f][0-9a-f]*', ...) [/code]

Member Avatar for blacknred
0
86

The End.