2,646 Posted Topics

Member Avatar for arindam31

[QUOTE=arindam31;1614313]Oh and one more thing......look at that link ouposted carefully......you will find my email adress too......thearc@gmail.com..........That idiot could have atleast changed that........really pathetic .............i cant believe it.........[/QUOTE] I think this site automatically crawls the web and publishes forum posts at random.

Member Avatar for arindam31
-1
239
Member Avatar for manni123

The best way I've found to do that is to run a ssh server on the remote machine and use the paramiko module. Here is a possible client code [code=python] import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect("IP_ADDRESS", username="USER", password="PASSWORD", allow_agent = False) i, o, e = ssh.exec_command("cp foo bar") # …

Member Avatar for Gribouillis
0
3K
Member Avatar for theharshest

You can find all the matches with finditer() and then select the last one [code=python] import re line = '<tr align="right"><td>3</td><td>Matthew</td><td>Brittany</td>' matches = list(re.finditer(r'([a-zA-Z]+)(?:</td>)', line)) print "matches:", matches name = matches[-1].group(1) print "name:", name """ my output ---> matches: [<_sre.SRE_Match object at 0x7fe2548059c0>, <_sre.SRE_Match object at 0x7fe254805b58>] name: Brittany """ …

Member Avatar for Gribouillis
0
446
Member Avatar for fingerpainting

Use sorted() and itertools.groupby() [code=python] from itertools import groupby data = """ BBB AAA 111 CCC DDD 222 BBB AAA 333 EEE FFF 77 CCC DDD 99 """ def pair(item): return tuple(item[:2]) L = [x.strip().split() for x in data.strip().splitlines()] print L R = [ [x, y, str(sum(int(z[2]) for z in …

Member Avatar for TrustyTony
0
653
Member Avatar for DragonSlayerX

You can add a method to check validity. I also corrected a few other errors [code=python] from math import sin, acos class Triangle: def __init__(self,x,y,z): self.x = x self.y = y self.z = z if not self.is_valid(): raise ValueError, "Not A Valid Triangle" def perimeter(self): return sum(self.sides()) def area(self): x, …

Member Avatar for Gribouillis
0
132
Member Avatar for Gribouillis

This snippet defines a context [icode]autofilename()[/icode] to create an existing temporary file with a new name in python. Unlike the methods in the [icode]tempfile[/icode] module, it only gives a filename which exists within a 'with' block, instead of an open file. This is useful for example when a program needs …

Member Avatar for Gribouillis
1
300
Member Avatar for M.S.

[QUOTE=pyTony;1613113][CODE]>>> print(unicode(urllib2.unquote('%D8%A7%DB%8C%D9%84%D8%A7%D9%85'), 'utf8')) ایلام >>> print(u'ایلام'.encode('utf8')) Unsupported characters in input >>> [/CODE][/QUOTE] On my computer [code=python] >>> import urllib2 >>> urllib2.quote('ایلام') '%D8%A7%DB%8C%D9%84%D8%A7%D9%85' [/code]

Member Avatar for M.S.
0
165
Member Avatar for lrh9

I know a very simple system called py-notify. See here [url]http://home.gna.org/py-notify[/url]. It define 'signals' emitted by your code, which can be 'connected' to callback functions.

Member Avatar for lrh9
0
116
Member Avatar for Archenemie

[QUOTE=Archenemie;1611765][CODE]import socket socket.create_connection(("localhost", "2000")) print "done" error: [Errno 10061] No connection could be made because the target machine actively refused it[/CODE] Why does my machine refuse the connection? how do i get around this? Thanks[/QUOTE] Why don't you run the example servers and clients programs in the documentation of the …

Member Avatar for Tech B
0
278
Member Avatar for rhuffman8

Also the decimal module exists in python 2.6. According to the source code, it was written in 2004 for python 2.3. If you need it, use it, either by upgrading to a version of python with the decimal module, or by using the attached version

Member Avatar for Gribouillis
0
240
Member Avatar for Cesiumlifeboat

[QUOTE=lrh9;1612697][COLOR="Green"]creature.metabolism[/COLOR] [COLOR="Red"]creature.metabolsim[/COLOR][/QUOTE] Sorry lrh9, I wanted to upvote your post and I downvoted it by mistake. Perhaps a moderator can change my vote, thanks :(

Member Avatar for Gribouillis
0
165
Member Avatar for Joeflims

A similar problem was solved in another forum. Try their solution [url]http://stackoverflow.com/questions/4676433/solving-dll-load-failed-1-is-not-a-valid-win32-application-for-pygame[/url]

Member Avatar for Joeflims
0
183
Member Avatar for rhuffman8

The error means that one of the records does not have length 8. The first solution is to print it to see what happens [code=python] from itertools import islice for i, record in islice(enumerate(reader), 1, None): if len(record) != 8: raise ValueError, "Bad record at line %d : %s" % …

Member Avatar for rhuffman8
0
373
Member Avatar for D33wakar

I don't know Microsoft's lcc, but you should probably link against the python library (something like -lpy27 or -lpython ...). Also did you run the code in the linking requirements section [code=python] >>> import distutils.sysconfig >>> distutils.sysconfig.get_config_var('LINKFORSHARED') [/code] to get flags for the linker ?

Member Avatar for D33wakar
0
397
Member Avatar for bmanzana

Simply unindent the last line out of the 'for' loop [code=python] key1 = [' ','a','b','c','0','1','2','3'] out = '' inpt = raw_input('enter text:') for i in inpt: if i in key1: out = out + key1[key1.index(i)+3] print out [/code]

Member Avatar for bmanzana
0
106
Member Avatar for Charly-Garcia

Also [code=python] def parse(line, pairs): a = 0 for n, rep in pairs: for i in range(rep): yield line[a:a+n] a += n pattern = [(9,1), (8,2), (7,4)] line = "abcdefgh: 1234 5678 45 45 45 45" print( tuple(parse(line, pattern)) ) """ my output --> ('abcdefgh:', ' 1234 ', ' 5678 …

Member Avatar for Gribouillis
0
158
Member Avatar for felix001

It would be better to compute with floating numbers to avoid division issues (like 5/9 == 0) [code=python] def nearest_int(number): return int(number + (0.5 if number >= 0 else -0.5)) print "%d Degrees Farenheit" % nearest_int(float(fc) * 9 / 5 + 32) [/code] Also it would be much better to …

Member Avatar for Gribouillis
0
194
Member Avatar for Bosterk

[QUOTE=Bosterk;1610531]thanks for your response sir, could you tell me how to do to query data in a database please?[/QUOTE] Perhaps start by reading the documentation, which contains examples [url]http://docs.python.org/library/sqlite3.html#module-sqlite3[/url]

Member Avatar for Gribouillis
0
302
Member Avatar for Pprog

[QUOTE=snippsat;1609196]For 2.6 you can do it like this. [CODE]>>> l = ['162.10.2.1', '162.10.2.1', '162.10.2.1', '192.34.1.10', '172.11.2.9'] >>> d = {} >>> for v in l: d[v] = d.get(v, 0) + 1 ... >>> d {'162.10.2.1': 3, '172.11.2.9': 1, '192.34.1.10': 1} >>> for k,v in sorted(d.iteritems()): ... print '%s - %s' …

Member Avatar for Gribouillis
0
2K
Member Avatar for M.S.

It works for me and python 2.6 [code=python] codes=['zlib', 'zip', 'base64', 'hex', 'utf-8'] def encoder(str, i): return str.encode(codes[i]) def decoder(str, i): return str.decode(codes[i]) thing = 'Some string here' for i, k in enumerate(codes): en = encoder(thing, i) assert thing == decoder(en, i) print "success" [/code]

Member Avatar for M.S.
0
109
Member Avatar for xleon

You can bind each page of the notebook (each page is a Frame) [code=python] title = 'Pmw.NoteBook demonstration' # Import Pmw from this directory tree. import sys sys.path[:0] = ['../../..'] import Tkinter import Pmw class Demo: def __init__(self, parent): # Create and pack the NoteBook. notebook = Pmw.NoteBook(parent) self.notebook = …

Member Avatar for xleon
0
349
Member Avatar for duffsil

You must store the averages somewhere in the instance [code=python] # -*- coding: cp1252 -*- import wx from functools import partial class duff(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,parent,wx.ID_ANY,'Duffan Formula', size=(400,370)) #wx.ID_ANY self.panel = wx.Panel(self) #self.panel #self.panel on all g=wx.StaticText(self.panel,-1,"________________________________________________________",pos=(10,65)) z=wx.StaticText(self.panel,-1,"Welcome to Duffan Formula!!",pos=(10,10)) r=wx.StaticText(self.panel,-1,"Here you can discover the score of any girl …

Member Avatar for duffsil
0
166
Member Avatar for machine91

It's pretty easy: [code=python] from threading import Thread from Queue import Queue # first create the 2 queues you need quxxx = Queue(10) quyyy = Queue(10) # then write the functions that the 2 threads will execute. # in the functions, put and get items from the queues as you …

Member Avatar for Gribouillis
0
266
Member Avatar for M.S.

Hint [code=python] >>> list1 = range(10) >>> list2 = range(100, 110) >>> list1 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list2 [100, 101, 102, 103, 104, 105, 106, 107, 108, 109] >>> list3 = zip(list1, list2) >>> list3 [(0, 100), (1, 101), (2, 102), (3, 103), …

Member Avatar for M.S.
0
538
Member Avatar for flebber

If you don't need to preserve order, the simplest is to use a set [code=python] >>> x = [2,3,1,3,5,4,5] >>> list(set(x)) [1, 2, 3, 4, 5] [/code] If you need to preserve order, there are also 2 functions in the recipes of the itertools module documentation: [code=python] from itertools import …

Member Avatar for TrustyTony
0
301
Member Avatar for hughesadam_87

[QUOTE=shoemoodoshaloo;1602426]Hey guys, I am writing a GUI program, and one of the routines requires that I choose a file to be my data file. If the data file is chosen correctly, then my program will send it to a subroutine which will perform a bunch of methods and ultimately construct …

Member Avatar for hughesadam_87
0
138
Member Avatar for magnetic rifle

[QUOTE=magnetic rifle;1602276]Is it possible to assign a variable to be a random vector. The only syntax I could find was rand.jumpahead but further research did not seem promising. Thank you, Suhail[/QUOTE] You should check the module numpy.random, which contains routines to generate random numpy arrays (convertible to python lists if …

Member Avatar for Gribouillis
0
160
Member Avatar for debasishgang7

Use functions hexlify() and unhexlify() in module binascii for this [code=python] >>> from binascii import hexlify, unhexlify >>> s = '\x01\x00\x12\x59' >>> h = hexlify(s) >>> print h 01001259 >>> assert unhexlify(h) == s >>> [/code]

Member Avatar for debasishgang7
0
1K
Member Avatar for Lolalola

There is a module called pyPdf which extracts data from pdf files. I don't use it myself, but I think it should solve a part of your problem. [url]http://pybrary.net/pyPdf/[/url]

Member Avatar for Gribouillis
0
53
Member Avatar for magnetic rifle

[QUOTE=magnetic rifle;1601517]Nothing changed[/QUOTE] The problem is that when you print a list, it prints the repr() of the list elements. To remove the quotation marks, you must apply str() to each element and join the results with commas [code=python] >>> import random >>> from string import ascii_lowercase as alpha >>> …

Member Avatar for magnetic rifle
0
9K
Member Avatar for user45949219

You can write [code=python] new_ageList = list() for age in ageList: if age < average: new_ageList.append(age) [/code] But it can be shortened using the list comprehension syntax: [code=python] new_ageList = [age for age in ageList if age < average] [/code]

Member Avatar for TrustyTony
0
155
Member Avatar for zidaine

[QUOTE=zidaine;1600474]why is it that when i pop a dictionary in variable b, variable a does the same? And When i print variable a, the value is [{'b':2}]. How can i retain the value of variable a? [CODE] a=[{'a':1,},{'b':2,}] b = a b.pop(0)[/CODE][/QUOTE] You must copy the list pointed to by …

Member Avatar for TrustyTony
0
138
Member Avatar for jodata26

You could start by running the examples of the sticky thread above [url]http://www.daniweb.com/software-development/python/threads/191210[/url]

Member Avatar for SamarthWiz
0
386
Member Avatar for TrustyTony

Here is how I would code it to get rid of the 'rotation' argument and make it a little faster [code=python] def strrot(string_seq, times = 1): times %= 4 if times % 2: string_seq = reversed(zip(*string_seq)) if times == 1 else zip(*reversed(string_seq)) return [''.join(t) for t in string_seq] else: return …

Member Avatar for Archenemie
1
703
Member Avatar for shurshot

[QUOTE=shurshot;1598165]Hi all, I'm new to this forum and I am also new to Python and coding in general. While I've gotten through basic tutorials on most general topics of Python such as series, dictionary, parameters, loops, and so forth I am still very much a newbie (as you will see …

Member Avatar for TrustyTony
0
353
Member Avatar for saurav4ever

Hello, The error means that one of your files has less than 2 lines. Here is a modified version which prints those files [code=python] #! /usr/bin/env python import sys import glob def doit(n): file_names = glob.glob('*/*.pdbqt') everything = [] for file_name in file_names: file = open(file_name) lines = file.readlines() file.close() …

Member Avatar for Gribouillis
0
333
Member Avatar for rickyfre

Hm, it could be a firewall issue. Normally, idle uses the port 8833. You may have to open this port on your firewall.

Member Avatar for vegaseat
0
105
Member Avatar for maf_9000

You could use a modified file object which sleeps between the lines. The following code works for me [code=python] # python 2 HOST, USER, PASSWD = "", "", "" # <--- your values here from ftplib import FTP from time import sleep class SlowFile(object): def __init__(self, name, mode="r", delay = …

Member Avatar for Gribouillis
0
1K
Member Avatar for Vengful

You can loop indefinitely with [icode]while True[/icode]. Here is the code [code=python] import random import re print 'This is a guessing game' def game(guess): x=random.randint(1,100) while True: # loop indefinitely respond = int(raw_input(guess)) # better than input() if respond < x: print 'nop higher' elif respond > x: print 'wow …

Member Avatar for Vengful
0
94
Member Avatar for SasseMan
Re: CMD

There is a specialized module for this called pexpect [url]http://www.noah.org/wiki/pexpect[/url] . It may, or may not suit your needs. The more general method is to communicate with the subprocess with pipes. For this you must use subprocess.Popen() instead of os.system(). See the documentation of module subprocess, and perhaps this blog …

Member Avatar for Gribouillis
0
152
Member Avatar for clyt

You are splitting each record 52 times. It's very inefficient. Perhaps you could speed things up with [code=python] rows = [ record.split() for record in file ] # warning: contains megabytes ncols = len(rows[0]) cols = [ [record[i] for record in rows] for i in xrange(ncols) ] # doubling the …

Member Avatar for clyt
0
138
Member Avatar for Caraka
Member Avatar for Caraka
0
869
Member Avatar for jmark13

To start with, here is a function wich transforms your input data into a python list, which should be easier to handle than a string [code=python] # stringgame.py import re word_re = re.compile(r"[AB01]+") def sub_func(match): """helper for parse()""" return "'%s'," % match.group(0) def parse(data): """transform an input string into a …

Member Avatar for TrustyTony
0
139
Member Avatar for Petan Kl

I think if you really target a fast operation for matrices with tens of thousands of numbers, you should write your own C function to perform the multiplication and wrap it either with the Instant module [url]http://heim.ifi.uio.no/~kent-and/software/Instant/doc/Instant.html[/url] if you have a linux system, or with swig [url]http://swig.org/[/url] if you don't, …

Member Avatar for Gribouillis
0
214
Member Avatar for FALL3N

In python a 'variable' is usually called a 'name'. Each name belongs to a certain 'namespace' which is a python dictionary. Here, your statement [icode]def testF(): ...[/icode] inserts the name "testF" in the global namespace, which is accessible by calling [icode]globals()[/icode]. So your reflect function could be written [code=python] def …

Member Avatar for FALL3N
0
279
Member Avatar for jml101
Member Avatar for vegaseat
0
721
Member Avatar for TrustyTony

An alternative way to explore your modules is to start a pydoc server and visit it with your web browser. Here is how it goes in linux [code=text] $ pydoc -p 9999& [1] 7877 $ pydoc server ready at http://localhost:9999/ [/code] It shows hundreds of modules for me to explore …

Member Avatar for Gribouillis
0
304
Member Avatar for rickyfre

In python 2.6, I have both [code=python] >>> import wx >>> wx.Color <class 'wx._gdi.Colour'> >>> wx.Colour <class 'wx._gdi.Colour'> [/code] You could add a piece of code like [code=python] import wx if hasattr(wx, "Color"): wx.Colour = wx.Color else: wx.Color = wx.Colour [/code]

Member Avatar for rickyfre
0
399
Member Avatar for 7sisters

I think you could follow an algorithm similar to this one: [code=python] >>> print A ['h', 'e', 'l', 'l', 'o', ' ', 'd', 'a', 'n', 'i', 'w', 'e', 'b'] >>> print B ['t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', 'n', ' ', 'e', 'x', 'a', 'm', …

Member Avatar for 7sisters
0
163
Member Avatar for hszforu

Don't indent python code with tab characters. Configure your editor to insert 4 spaces instead of a tab when you hit the tab key. Also reindent your code like this [code=python] def print_lol(movies): for each in movies: if isinstance(each,list): print_lol(each) else: print(each) [/code] I used the "reindent" script to reindent …

Member Avatar for Gribouillis
0
928

The End.