2,646 Posted Topics
Re: [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. | |
Re: 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") # … | |
Re: 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 """ … | |
Re: 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 … | |
Re: 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, … | |
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 … | |
Re: [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] | |
Re: 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. | |
Re: [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 … | |
Re: 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 | |
Re: [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 :( | |
Re: 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] | |
Re: 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" % … | |
Re: 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 ? | |
Re: 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] | |
Re: 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 … | |
Re: 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 … | |
Re: [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] | |
Re: [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' … | |
Re: 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] | |
Re: 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 = … | |
Re: 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 … | |
Re: 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 … | |
Re: 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), … | |
Re: 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 … | |
Re: [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 … | |
Re: [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 … | |
Re: 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] | |
Re: 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] | |
Re: [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 >>> … | |
![]() | Re: 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] |
Re: [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 … | |
Re: You could start by running the examples of the sticky thread above [url]http://www.daniweb.com/software-development/python/threads/191210[/url] | |
Re: 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 … | |
Re: [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 … | |
Re: 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() … | |
![]() | Re: Hm, it could be a firewall issue. Normally, idle uses the port 8833. You may have to open this port on your firewall. |
Re: 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 = … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: I suggest [code=python] entry0 = "'{e:0>7}'".format(e=entry[0]) [/code] | |
Re: 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 … | |
Re: 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, … | |
Re: 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 … | |
Re: I don't think the OP is still waiting for the answer after 3 years :) | |
Re: 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 … | |
![]() | Re: 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] ![]() |
Re: 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', … | |
Re: 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 … |
The End.