Random image downloader for newsgroups (first script)
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the image or save it. This is my first script so be gentle! Heres the script random group downloader import nntplib import string, random import mimetools import StringIO import rfc822 import sys, base64 import os import email import errno import mimetypes SERVER = "news.server.co.uk" #Insert news server here GROUP = "alt.binaries.pictures.blah" #newsgroup will go here # connect to server server = nntplib.NNTP(SERVER) resp, count, first, last, name = server.group(GROUP) for i in range(10): try: id = random.randint(int(first), int(last)) resp, id, message_id, text = server.article(str(id)) except (nntplib.error_temp, nntplib.error_perm): pass # no such message (maybe it was deleted?) else: break # found a message! else: raise SystemExit text = string.join(text, "\n") file = StringIO.StringIO(text) msg = mimetools.Message(file) #display message information #print "File type", "=>", msg.gettype() #print "Encoding", "=>", msg.getencoding() #print "plist", "=>", msg.getplist() message = rfc822.Message(file) for k, v in message.items(): print k, "=", v file = message.fp.read() def yenc_decode(file): # find body while 1: line = file.readline() if not line: return None if line[:7] == "=ybegin": break # extract data buffer = [] while 1: line = file.readline() if not line or line[:5] == "=yend": break if line[-2:] == "\r\n": line = line[:-2] elif line[-1:] in "\r\n": line = line[:-1] data = string.split(line, "=") buffer.append(string.translate(data[0], yenc42)) for data in data[1:]: data = string.translate(data, yenc42) buffer.append(string.translate(data[0], yenc64)) buffer.append(data[1:]) return buffer #the following should write to a text file #inp = ("file","r") #outp = open("text.txt","w") #for line in file: #outp.write(line) #print file #outp.close() --= Posted using GrabIt = --= Binary Usenet downloading made easy =- -= Get GrabIt for free from http://www.shemes.com/ =- -- http://mail.python.org/mailman/listinfo/python-list
Random news downloader (first script!)
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the image or save it. This is my first script so be gentle! Heres the script random group downloader import nntplib import string, random import mimetools import StringIO import rfc822 import sys, base64 import os import email import errno import mimetypes SERVER = "news.server.co.uk" #Insert news server here GROUP = "alt.binaries.pictures.blah" #newsgroup will go here # connect to server server = nntplib.NNTP(SERVER) resp, count, first, last, name = server.group(GROUP) for i in range(10): try: id = random.randint(int(first), int(last)) resp, id, message_id, text = server.article(str(id)) except (nntplib.error_temp, nntplib.error_perm): pass # no such message (maybe it was deleted?) else: break # found a message! else: raise SystemExit text = string.join(text, "\n") file = StringIO.StringIO(text) msg = mimetools.Message(file) #display message information #print "File type", "=>", msg.gettype() #print "Encoding", "=>", msg.getencoding() #print "plist", "=>", msg.getplist() message = rfc822.Message(file) for k, v in message.items(): print k, "=", v file = message.fp.read() def yenc_decode(file): # find body while 1: line = file.readline() if not line: return None if line[:7] == "=ybegin": break # extract data buffer = [] while 1: line = file.readline() if not line or line[:5] == "=yend": break if line[-2:] == "\r\n": line = line[:-2] elif line[-1:] in "\r\n": line = line[:-1] data = string.split(line, "=") buffer.append(string.translate(data[0], yenc42)) for data in data[1:]: data = string.translate(data, yenc42) buffer.append(string.translate(data[0], yenc64)) buffer.append(data[1:]) return buffer #the following should write to a text file #inp = ("file","r") #outp = open("text.txt","w") #for line in file: #outp.write(line) #print file #outp.close() --= Posted using GrabIt = --= Binary Usenet downloading made easy =- -= Get GrabIt for free from http://www.shemes.com/ =- -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a python c-module: passing double arrays to c functions. segmentation fault. swig
thanks a lot, sturlamolden, for the quick reply! so i tried to use numpy and ctypes as you advised and i got it working: with some little changes for my linux machine - i hope they aren't the cause of the results: to load it, i only got it going with LoadLibrary: lib = numpy.ctypeslib.load_library("_timewarpsimple.so",".") _timewarp = lib.timewarp i replaced double by c_double: array_pointer_t = ndpointer(dtype=c_double) and i needed to define a restype, too: _timewarp.restype = c_double so, the strange errors with lots of stack traces are gone, but for large lists i got the same problem: Segmentation fault. for example for the following two lines: list1,list2 = numpy.array([0.1 for i in range(999)]), numpy.array([0.7 for i in range(1041)]) print timewarp(list1,list2) So it is maybe more of a c problem, but still, if i copy the big arrays into my c code, everything works out just fine (x[]={0.1,0.1,... }...) so it may still have something to do with the python-c interface and memory allocation or something like that. below i put my new shorter python script, the c and the rest hasn't changed. what can i try now? thanks again kim import numpy import ctypes from numpy.ctypeslib import ndpointer from ctypes import c_int,c_double lib = numpy.ctypeslib.load_library("_timewarpsimple.so",".") _timewarp = lib.timewarp #_timewarp = ctypes.cdll.timewarp.timewarp # timewarp.dll array_pointer_t = ndpointer(dtype=c_double) _timewarp.argtypes = [array_pointer_t, c_int, array_pointer_t, c_int] _timewarp.restype = c_double def timewarp(x, y): lenx, leny = x.shape[0], y.shape[0] print lenx,leny return _timewarp(x, lenx, y, leny) # testing: list1,list2 = numpy.array([0.1 for i in range(999)]), numpy.array([0.7 for i in range(1041)]) print timewarp(list1,list2) for x in range(999,): for y in range(999,): list1,list2 = [0.1 for i in range(x)], [0.9 for i in range(y)] print len(list1),len(list2),len(list1)+len(list2) list1,list2 = numpy.array(list1), numpy.array(list2) print timewarp(list1,list2) On Mar 30, 10:56 pm, sturlamolden <[EMAIL PROTECTED]> wrote: > On 30 Mar, 22:21, [EMAIL PROTECTED] wrote: > > > Hello everybody, > > > I'm building a python module to do some heavy computation in C (for > > dynamic time warp distance computation). > > Why don't you just ctypes and NumPy arrays instead? > > # double timewarp(double x[], int lenx, double y[], int leny); > > import numpy > import ctypes > from numpy.ctypeslib import ndpointer > from ctypes import c_int > > _timewarp = ctypes.cdll.timewarp.timewarp # timewarp.dll > array_pointer_t = ndpointer(dtype=double) > _timewarp.argtypes = [array_pointer_t, c_int, array_pointer_t, c_int] > > def timewarp(x, y): >lenx, leny = x.shape[0], y.shape[0] >return _timewarp(x, lenx, y, leny) -- http://mail.python.org/mailman/listinfo/python-list
Re: are int, float, long, double, side-effects of computer engineering?
On 03/06/2012 01:34 AM, Xah Lee wrote: while what you said is true, but the problem is that 99.99% of programers do NOT know this. They do not know Mathematica. They've never seen a language with such feature. The concept is alien. This is what i'd like to point out and spread awareness. I can see your point. But that's not simply true. In my case and many others, such issue was addressed during first week of introductory programming classes. I was naively thought "computer = precision" and I was stunned to find out the inaccuracy of computer calculations. But as you experienced, I also stumble upon some people (specially Java only programmers) who were not aware of it. also, argument about raw speed and fine control vs automatic management, rots with time. Happened with auto memory management, managed code, compilers, auto type conversion, auto extension of array, auto type system, dynamic/scripting languages, etc. Maybe it's because I'm not in scientific community, that I learned to live with such side-effects. Because 99.99% of computer users and programmers can afford to, and willing to lose such small inaccuracy billion times in exchange for some performance increase and convenience. Although NASA may not accept my application for their projects for Mars mission after this posting. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Plausible Promise of Abundant Educational Resources
Google search for slidespeech returns with a warning, "This site may harm your computer." -- http://mail.python.org/mailman/listinfo/python-list
unable to import os
Fredrik Lundh,I replaced mtime = os.stat(Path + file_name)[os.path.stat.ST_MTIME] with mtime = nt.stat("q.py") per your suggested, then ran it from IDLE 2.4.2. Here is the message I got, Traceback (most recent call last): File "C:\Documents and Settings\nguyeki\Desktop\Oct7", line 37, in -toplevel- main() File "C:\Documents and Settings\nguyeki\Desktop\Oct7", line 17, in main mtime = nt.stat("q.py") OSError: [Errno 2] No such file or directory: 'q.py' I did the search and could not find the file "q.py". -- http://mail.python.org/mailman/listinfo/python-list
output question 1
I wrote the following code and got the output:a 13 0Noneb 81 3Nonec 8 2Noned 9 2Nonee 1 1Nonewhere are those 'none' from? and how can I remove them? class Point: def __init__(self,x,y,name): self.x = x self.y = y self.name = name def summary(self): print self.name,self.x,self.yif __name__ == '__main__': from string import letters m = 13,81,8,9,1 n = 0,3,2,2,1 q=len(x) points = [ Point(m[i],n[i],letters[i]) for i in range(q) ] i=0 while i print points[i].summary() i=i+1 -- http://mail.python.org/mailman/listinfo/python-list
Re: bicyclerepairman python24 windows idle :(
EuGeNe wrote: > Hi there, > > I am no expert but wanted to give bicyclerepairman 0.9 a go just to see > what a refactoring browser is and does. Followed every step of the > install, I think, but idle doesn't start with the RepairMan section in > config-extensions.def ... is it incompatible with 2.4? > > Thanks for your help. > > -- > EuGeNe There seems to be a change in idlelib in Python 2.4. Apply following patch to BicycleRepairMan_Idle.py: @@ -87,6 +87,7 @@ mbar = editwin.menubar editwin.menudict[name] = menu = Menu(mbar, name = name) mbar.add_cascade(label = label, menu = menu, underline = underline) +self.editwin.fill_menus(self.menudefs) # Initialize Bicyclerepairman and import the code path = self.editwin.io.filename -- http://mail.python.org/mailman/listinfo/python-list
Re: Well, another try Re: while c = f.read(1)
Robert Kern wrote: > http://www.catb.org/~esr/faqs/smart-questions.html Is it a *smart* way or *necessary* way? Plus, my question was not for the detail description but for the intuitive guide leading the beginner's further study. I understand that too many repeated talks make cyberian tired. However, over and over discussions of basic concepts is also very important for technology enhancements. Thus, Commands 'iter' and 'lambda' should be discussed over and over about their necessity and convenience in the news-group as long as they are the principle keywords distinguished from the conventional languages like c/c++, pascal, etc. -James -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
Jeff Schwab wrote: > 5. Scripting is easier in Python than in Java, particularly with > regard to environment variables and process control. > > Of course, these are only my opinions. I am particularly not an expert > on Python or Java. Note that for Java experts, Jython can be used for interpreting works. Jython has the same grammer to Python, or CPython, and is also able to call Java codes very simply. See, for example: http://www.jython.org/docs/usejava.html -James (^o^) -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
Wouter van Ooijen (www.voti.nl) wrote: > I use Python when my time is most valuable (in most cases it is), in > the very few cases the computer's time is more valuable I write in > C/C++. In cases when the computer's time is more valuable, why not use CPython with C/C++ API? Only most time consuming parts can be replaced to C/C++ codes so as to increase the speed up to native C/C++ programs). -James (^o^) -- http://mail.python.org/mailman/listinfo/python-list
IDLE Problem: win98\Python2.4
This sure seems like it would have been brought up but I checked Google Groups (the dejanews replacement) and saw nothing: I installed Python2.4 in Win98 and IDLE doesn't work (neither does the online manual even tho a 3.6KB Python24.chm is there, but that's a story for another day) - that is, clicking on the IDLE icon in the Start menu just gives a brief hourglass cursor and then nothing . . . >From a DOS prompt (in C:\Python24) I can do 'python lib\idlelib\idle.py' and get a list of errors, not being able to find tcl8.4 in a number of paths, none of which exist in the c:\python24 as installed. I moved tcl84.lib into a directory it does search and got fewer errors msg's, the last being like 'can't find a usable init.tcl.' Moved init.tcl to the same dir as tcl84.lib, got even fewer errors, the last being like "_tkinter.TclError: invalid cmd name "tcl_findLibrary" So I'm stuck. I uninstalled Py2.4, installed Py2.3.5, again same thing . . . IDLE just does not come up with the tcl paths of the standard install. www.python.org gives answer to problems w/IDLE on Py1.5 from 1999 and shows adding tcl\bin to %PATH%. OK . . . What to try next? SOMEONE else must have seen this? \kim -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE Problem: win98\Python2.4
> kim kubik wrote: > > I installed Python2.4 in Win98 > > and IDLE doesn't work > Are you also running Ruby? The Ruby bundle for MS Windows has caused > problems with it's TCL package conflicting with Python's. > thanks, one of the first things I noted in the error msg (not included for brevity) was that the ruby search path in AUTOEXEC.BAT was ahead of the python path (and ruby had tcl83.lib) so I REM'd all the tcl stuff out. AND THEN (stupid me!) I put into AUTOEXEC.BAT 'set TCL_LIBRARY=c:\python23\tcl' thinking that would point python to the proper libs. What a mistake! If I take that line out (and leave the ruby stuff REM'd out as well) IDLE runs just fine. So thanks! A little knowledge is indeed a dangerous thing; forgive my stupidity - it will happen again, so I'm apologizing in advance! \kim -- http://mail.python.org/mailman/listinfo/python-list
Need some help to understand Python program..
Hi,,, I am very interested about the following Python program, but I am very beginner on Python.. I do not understand this algorithm,, I would appreciated if you give me this algorithm to some other popular programming language. filename="Karp.py" from __future__ import nested_scopes import bisect class _Num: def __init__(self, value, index): self.value = value self.i = index def __lt__(self, other): return self.value < other.value # This implements the Karmarkar-Karp heuristic for partitioning a set # in two, i.e. into two disjoint subsets s.t. their sums are # approximately equal. It produces only one result, in O(N*log N) # time. A remarkable property is that it loves large sets: in # general, the more numbers you feed it, the better it does. class Partition: def __init__(self, nums): self.nums = nums sorted = [_Num(nums[i], i) for i in range(len(nums))] sorted.sort() self.sorted = sorted def run(self): sorted = self.sorted[:] N = len(sorted) connections = [[] for i in range(N)] while len(sorted) > 1: bigger = sorted.pop() smaller = sorted.pop() # Force these into different sets, by "drawing a # line" connecting them. i, j = bigger.i, smaller.i connections[i].append(j) connections[j].append(i) diff = bigger.value - smaller.value assert diff >= 0 bisect.insort(sorted, _Num(diff, i)) # Now sorted contains only 1 element x, and x.value is # the difference between the subsets' sums. # Theorem: The connections matrix represents a spanning tree # on the set of index nodes, and any tree can be 2-colored. # 2-color this one (with "colors" 0 and 1). index2color = [None] * N def color(i, c): if index2color[i] is not None: assert index2color[i] == c return index2color[i] = c for j in connections[i]: color(j, 1-c) color(0, 0) # Partition the indices by their colors. subsets = [[], []] for i in range(N): subsets[index2color[i]].append(i) return subsets N = 50 import math x = [math.sqrt(i) for i in range(1, N+1)] p = Partition(x) s, t = p.run() sum1 = 0L sum2 = 0L for i in s: sum1 += x[i] for i in t: sum2 += x[i] print "Set 1 sum", repr(sum1) print "Set 2 sum", repr(sum2) print "difference", repr(abs(sum1 - sum2)) Thanks for you help... -- http://mail.python.org/mailman/listinfo/python-list
Re: Hello
See message below. On Fri, Dec 11, 2015 at 1:13 PM, Seung Kim wrote: > I would like to have Python 3.5.1 MSI installer files for both 32-bit and > 64-bit so that I can deploy the software on managed computers on campus. > > When I ran the silent install command line on python-3.5.1.exe, the > registry key of QuietUninstallString showed me that the installer file was > located under the following C:\Users\css.kim\AppData\Local\Package > Cache\{b8440650-9dbe-4b7d-8167-6e0e3dcdf5d0}\python-3.5.1-amd64.exe" > /uninstall /quiet. > > If I deploy the latest version of Python 3.5.1, the source location will > be differently installed among managed computers. That is why I won't use > the exe installer file. I wanted to have MSI installer files. > > Please, advise. > > -- > > > Seung Kim > Software Systems Deployment Engineer > Gallaudet Technology Services, Hall Memorial Building (HMB) W122 > Gallaudet University > 800 Florida Avenue, NE > Washington, D.C. 20002-3695 > -- Seung Kim Software Systems Deployment Engineer Gallaudet Technology Services, Hall Memorial Building (HMB) W122 Gallaudet University 800 Florida Avenue, NE Washington, D.C. 20002-3695 -- https://mail.python.org/mailman/listinfo/python-list
Plotting the integer-and-fraction remainder of a function value modulo 360
How can I get Python to represent a value of a function in degrees, i.e., with values between 0 and 360, by taking the (non-integer) function expression mod 360? That is, I have a function with non-integer values, called Longitude, which is defined in terms of the variable t. I just want to plot Longitude modulo 360 for a range of values of t: that is, for every value of t, plot the integer-AND-fraction remainder after dividing Longitude by 360. But Python (in Sage) apparently won't let me use the int function or the // operator on functions defined in terms of a variable: I get a "cannot evaluate symbolic expression numerically" TypeError. How do I do this? There must be a simple way to tell Python that I want it to compute the value of Longitude for a given value of t and then take the integer-and-fraction remainder from dividing by 360. Many thanks, Kim-- https://mail.python.org/mailman/listinfo/python-list
Re: Plotting the integer-and-fraction remainder of a function value modulo 360
Thanks! As I recently posted in a followup message, Here's an example of what goes wrong: t = var('t') L(t) = t*725.5%360.0 This produces the following error message: ... TypeError: unsupported operand type(s) for %: 'sage.symbolic.expression.Expression' and 'sage.symbolic.expression.Expression' So it looks like I've got a Sage-specific problem. I still don't know how to fix it, but at least I understand the problem better! Many thanks, Kim From: Steven D'Aprano To: python-list@python.org Sent: Thursday, April 10, 2014 1:01 AM Subject: Re: Plotting the integer-and-fraction remainder of a function value modulo 360 On Wed, 09 Apr 2014 21:32:27 -0700, Kim Plofker wrote: > How can I get Python to represent a value of a function in degrees, > i.e., with values between 0 and 360, by taking the (non-integer) > function expression mod 360? > > That is, I have a function with non-integer values, called Longitude, > which is defined in terms of the variable t. I just want to plot > Longitude modulo 360 for a range of values of t: that is, for every > value of t, plot the integer-AND-fraction remainder after dividing > Longitude by 360. > > But Python (in Sage) apparently won't let me use the int function or the > // operator on functions defined in terms of a variable: I get a "cannot > evaluate symbolic expression numerically" TypeError. That's an issue with Sage itself, probably sympy. Python the language doesn't natively understand symbolic expressions, that's added by sympy, so you may need to ask some sympy experts. It may help if you show the actual code you are using, and the full traceback generated by the error. When I try something similar, I get a different error message: py> from sympy.abc import x py> (x + 1) % 60 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for %: 'Add' and 'int' which could mean I'm doing something different, or just a difference in version numbers. > How do I do this? > There must be a simple way to tell Python that I want it to compute the > value of Longitude for a given value of t and then take the > integer-and-fraction remainder from dividing by 360. That's simple with numeric types: use the divmod function or % operator. But you're using some sort of symbolic library, so we need to know what the library is. -- Steven -- https://mail.python.org/mailman/listinfo/python-list-- https://mail.python.org/mailman/listinfo/python-list
Re: Plotting the integer-and-fraction remainder of a function value modulo 360
Thanks, the % operator is indeed what I want, but I want to use it with a function expression rather than with numbers alone. And that seems to create a type error. Here's an example of what goes wrong: t = var('t') L(t) = t*725.5%360.0 This produces the following error message: ... TypeError: unsupported operand type(s) for %: 'sage.symbolic.expression.Expression' and 'sage.symbolic.expression.Expression' I can use other arithmetic operators such as + and / in this function expression, but not %, and I don't understand why. Is it indeed a Sage-specific problem rather than something I could work around in Python? Many thanks again for any help. Kim From: Ben Finney To: python-list@python.org Sent: Thursday, April 10, 2014 12:54 AM Subject: Re: Plotting the integer-and-fraction remainder of a function value modulo 360 Kim Plofker writes: > How can I get Python to represent a value of a function in degrees, > i.e., with values between 0 and 360, by taking the (non-integer) > function expression mod 360? In Python, you simply use the modulo (‘%’) operator:: >>> 45.0 % 360 45.0 >>> 700.0 % 360 340.0 >>> > That is, I have a function with non-integer values, called Longitude If they're not integers, and you're not saying what they *are*, then I can't know anything beyond “they will behave the way the Longitude class defines them”. > which is defined in terms of the variable t. I don't understand what it means for a longitude value to be “defined in terms of the variable t”. Can you say more about how these values are defined? Since (as you say) they're not integers, what *are* they? > I just want to plot Longitude modulo 360 for a range of values of t: > that is, for every value of t, plot the integer-AND-fraction remainder > after dividing Longitude by 360. What does it mean to “plot the integer-AND-fraction remainder”? It sounds like you want to plot two numbers separately, the integer and the fraction remainder. But that doesn't make much sense to me. Do you mean simply that you want to plot numbers like ‘3.7’, ‘270.0’, and ‘48.75’? In which case, this is supported by the native ‘float’ type, and (for better accuracy) by the ‘decimal.Decimal’ type from the standard library:: >>> lon = decimal.Decimal("758.45") >>> lon % 360 Decimal('38.45') > But Python (in Sage) apparently won't let me use the int function or > the // operator on functions defined in terms of a variable: I get a > "cannot evaluate symbolic expression numerically" TypeError. It sounds like this Sage is not behaving as the standard Python types do, with regard to the modulo ‘%’ operator. For help with Sage (I don't know what that is), you probably will get better answers on a Sage-specific discussion forum. From the perspective of Python, the standard types handle the requirements you describe without any TypeError. -- \ “If you were going to shoot a mime, would you use a silencer?” | `\ —Steven Wright | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list-- https://mail.python.org/mailman/listinfo/python-list
Marshaled input / output from Perforce server
I'm trying to write a script in python that communicates with a perforce server. I can get the output from perforce by using -G and the popen command. I have a problem when I'm trying to send a request to the server using marshaled input. I cannot find a single example anywhere on the net describing it. I would very much appreciate if anyone could provide a simple example, or a secret link or smth. And if there is any documentation on the specific API that is availble when using the marshaled input, could you please provide give a link. Thx in advance. Kim B. -- http://mail.python.org/mailman/listinfo/python-list
[python-list] pdf read & write
Dear all, How can I read a pdf file and add invisible comment? I want to make a script which read a pdf file and add tags inside the file invisibly. Then, I will make a script for managing tags of given pdf files. I know "referencer" can manage tags for pdf file but it seems store tag information to additional file outside pdf file. Any suggestion are welcome. Best, Hyunchul Kim -- http://mail.python.org/mailman/listinfo/python-list
[python-list] pdf read & write
Dear all, How can I read a pdf file and add invisible comment? I want to make a script which read a pdf file and add tags inside the file invisibly. Then, I will make a script for managing tags of given pdf files. I know "referencer" can manage tags for pdf file but it seems store tag information to additional file outside pdf file. Any suggestion are welcome. Best, Hyunchul Kim -- http://mail.python.org/mailman/listinfo/python-list
How to decompress .Z file?
Hi, all How can .Z file be decompressed? According to python library reference, .Z file might not be supported by python, yet. Best, Hyunchul Kim -- http://mail.python.org/mailman/listinfo/python-list
Re: Try to porting Python2.5 to Zaurus
Glad to see another Zaurus lovin' Pythonite. ;-) and also thanks to you -- http://mail.python.org/mailman/listinfo/python-list
how to find all completely connected sub-graphs?
Hi, all, How can I find all "completely connected subgraphs" in a graph when node and edge data are available? "completely connected subgraph" is a group, all members of which are connected to each other. Thanks, Hyunchul -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find all completely connected sub-graphs?
Dear Odeits, Yes, I meant directly connected to each other. Thanks. Hyunchul odeits wrote: On Mar 2, 10:35 pm, Hyunchul Kim wrote: Hi, all, How can I find all "completely connected subgraphs" in a graph when node and edge data are available? "completely connected subgraph" is a group, all members of which are connected to each other. Thanks, Hyunchul Do you mean all of the member are directly connected to each other? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: unbiased benchmark
In the system that I tested, results were different. * System was CPU: AMD Phenom(tm) 9950 Quad-Core Processor, Frequency 2600MHz, L2 cache 512KB Memory 3164MB OS: Ubuntu 8.10 When I tried this benchmark for the first time, i...@pc:~$ time python bench.py real0m0.010s user0m0.008s sys0m0.000s i...@pc:~$ time ruby bench.rb real0m0.108s user0m0.000s sys0m0.004s Python was faster than Ruby 10 times!! As I repeated, results showed shorter times and became stable. After a few repeat, stable results were i...@pc:~$ time python bench.py real0m0.010s user0m0.008s sys0m0.000s i...@pc:~$ time ruby bench.rb real0m0.004s user0m0.004s sys0m0.000s Now, Ruby is faster two times. Have you repeated your benchmark? Your results looks to be over-exaggeration even if this benchmark is fair. Hyunchul Sam Ettessoc wrote: Dear sir, I would like to share a benchmark I did. The computer used was a 2160MHz Intel Core Duo w/ 2000MB of 667MHz DDR2 SDRAM running MAC OS 10.5.6 and a lots of software running (a typical developer workstation). Python benchmark: HAMBURGUESA:benchmark sam$ echo 1+1 > bench.py HAMBURGUESA:benchmark sam$ time python bench.py real0m0.064s user0m0.049s sys 0m0.013s Ruby benchmark: HAMBURGUESA:benchmark sam$ echo 1+1 > bench.rb HAMBURGUESA:benchmark sam$ time ruby bench.rb real0m0.006s user0m0.003s sys 0m0.003s Can you believe it? Ruby is 10 times faster than Python. On a side note, when I subscribed to the Python mailing list, it took less than 200ms before I got the confirmation email. For the Ruby mailing list, it took over 9000ms! Which is 4500% less performant! Sam Ettessoc p.s. I have no affiliation with ruby or python devloppement team. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: how to convert from Decimal('1.23456789') to Decimal('1.234')
In that case, I usually use # when rounding is proper, s = '1.23456789' print round(float(s)) or # when cut out is proper, from math import floor print floor(float(s)*1000)/1000 Hyunchul valpa wrote: I only need the 3 digits after '.' Is there any way other than converting from/to string? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
speed of string chunks file parsing
Hi, all I have a simple script. Can you improve algorithm of following 10 line script, with a view point of speed ? Following script do exactly what I want but I want to improve the speed. This parse a file and accumulate lines till a line match a given regular expression. Then, when a line match a given regular expression, this function yield lines before the matched lines. import re resultlist = [] cp_regularexpression = re.compile('^a complex regular expression here$) for line in file(inputfile): if cp_regularexpression.match(line): if resultlist != []: yield resultlist resultlist = [] resultlist.append(line) yield resultlist Thank you in advance, Hyunchul -- http://mail.python.org/mailman/listinfo/python-list
Date type in win32com?
Hi. I'm migrating a VBScript into python. How should I convert Date type parameter in VBScript's COM interface with win32com? I couldn't find any answer yet... Thank you in advance. -- http://mail.python.org/mailman/listinfo/python-list
sum up numbers in a list
hi all, i have a list, for example; >>> L=[] >>> L.append('10') >>> L.append('15') >>> L.append('20') >>> len(L) 3 >>> print L ['10', '15', '20'] is there a way to sum up all the numbers in a list? the number of objects in the list is vary, around 50 to 60. all objects are 1 to 3 digit positive numbers. all i can think of is check the length of the list (in the above example, 3), then L[0]+L[1]+L[2] .. is there a better way to do the job? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: sum up numbers in a list
brilliant, thank you both of you, i will try that out later. :) On Wed, Aug 27, 2008 at 1:34 AM, c james <[EMAIL PROTECTED]> wrote: > >>> L=['10','15','20'] > >>> sum(int(x) for x in L) > 45 > > or > >>> sum(map(int,L)) > 45 > > > sharon kim wrote: > >> hi all, >> >> i have a list, for example; >> >> >>> L=[] >> >>> L.append('10') >> >>> L.append('15') >> >>> L.append('20') >> >>> len(L) >> 3 >> >>> print L >> ['10', '15', '20'] >> >> is there a way to sum up all the numbers in a list? the number of objects >> in the list is vary, around 50 to 60. all objects are 1 to 3 digit positive >> numbers. >> >> all i can think of is check the length of the list (in the above example, >> 3), then L[0]+L[1]+L[2] .. >> >> is there a better way to do the job? thanks. >> > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
how to save a modified .xml back
Hi all, I want to load a small .xml file, modifiy some nodes and save the .xml with modifications to another .xml file. I managed to load and modify a small .xml file using xml.dom.minidom and xml.dom.pulldom. However, I don't know how to save it back using any of two modules. Any suggestion? Thank you in advance, ** from xml.dom.pulldom import START_ELEMENT, parse doc = parse('input.xml') for event, node in doc: if event == START_ELEMENT and node.localName == "something_interesting": doc.expandNode(node) for an_element in node.childNodes: do_something() * Hyunchul -- http://mail.python.org/mailman/listinfo/python-list
sequential multiple processes
Hi, all How to run multiple processes with sequential input of a thousand of data in a script run? I have a python script and 1,000 independent input data for it. Previously, I divided input data into* n* groups and ran a same python script *n* times to use *n* processors. It's inconvenient. How can I do same thing in a signle script running? Thank you in advance, Hyunchul -- http://mail.python.org/mailman/listinfo/python-list
faster than list.extend()
Hi, all. I want to improve speed of following simple function. Any suggestion? ** def triple(inputlist): results = [] for x in inputlist: results.extend([x,x,x]) return results ** Thank you in advance, Hyunchul -- http://mail.python.org/mailman/listinfo/python-list
Re: faster than list.extend()
Thank Tim, Raymond, and all. In my test, Tim's t1 was fastest and Raymond's triple3 is very near to Tim's t1. Anyway both of them took only 6~7% time of my original .extend() version. I think that following n_ple() is a good generalized function that was 1~3% slower than t1() and triple3() for "triple". * from itertools import * def n_ple(inputlist, n): chain_from_iterable = chain.from_iterable; izip = izip return chain_from_iterable(izip(*[inputlist]*n)) * def t2(i): r = range(3) return (x for x in i for _ in r) def t2_1(i): r = range(3) return [x for x in i for _ in r] I didn't know that list(t2(inputlist)) is much faster than t2_1(inputlist), it's gonna be a helpful tip for me. Thank you all. Hyunchul On Tue, Nov 17, 2009 at 7:55 AM, Tim Chase wrote: > Hyunchul Kim wrote: > >> Hi, all. >> >> I want to improve speed of following simple function. >> Any suggestion? >> >> ** >> def triple(inputlist): >> results = [] >> for x in inputlist: >>results.extend([x,x,x]) >> return results >> ** >> > > Several ways occur to me: > > def t1(i): >for x in i: > yield x > yield x > yield x > > def t2(i): >r = range(3) >return (x for x in i for _ in r) > > > I prefer to return generators in case the input is large, but in both > cases, you can just wrap it in list() like > > list(t1(inputlist)) > > or in t2(), you can just change it to use > >return [x for x in i for _ in r] > > -tkc > > > > > -- http://mail.python.org/mailman/listinfo/python-list
LZO decompressing with Python 2.5x on Windows for C dummies
Hi list, I have some binary data files which contain embedded LZO compressed payloads mixed with normal C-struct like headers. I would like to have the ability to LZO decompress these payloads using a python 2.5.x script. I was hoping that there was an up-to-date plug-and-play LZO library available for Windows somewhere. However, I have not managed to find such a one. The closest I have gotten is on the official LZO home page: http://www.oberhumer.com/opensource/lzo/ There is a link to some old LZO 1.08 bindings for Python 2.2 there as a tar.gz (released back in 2002!) http://www.oberhumer.com/opensource/lzo/download/LZO-v1/python-lzo-1.08.tar.gz I managed to unpack that using the python tarfile module (very handy for the purpose) In essence, the tarball contains a setup.py lzomodule.c Makefile and some documentation It does not contain anything that appears to be binaries for Windows. The instructions indicate that I am supposed to build it myself using the Makefile. I do not have make nor a C-compiler installed, and I fear that if I were to compile it, it would be a very tedious process for me, and I would rather like to avoid it if at all possible. Concerning the Windows LZO binaries I have previously struggled with pytables and using LZO on Windows with HDF5 files, and in relation to that Francesc Alted was so kind to build Windows LZO ver. 1.08 binaries as discussed here http://www.pytables.org/moin/FAQ#A.5BWindows.5DCan.27tfindLZObinariesforWindows and available here as a zip file http://www.pytables.org/download/lzo-win Amongst others, this zip file has a Gwin32\bin\lzo1.dll file. By copying that to the ptables filder in my python25 installation I have managed to get LZO working with pytables. Getting back to the python bindings, the setup.py does contain a section, which indicates that it adresses a Windows platform also: ... if sys.platform == "win32": # Windows users have to configure the LZO_DIR path parameter to match # their LZO source installation. The path set here is just an example # and thus unlikely to match your installation. LZO_DIR = r"c:\src\lzo-1.08" include_dirs.append(os.path.join(CURL_DIR, "include")) extra_objects.append(os.path.join(CURL_DIR, "lzo.lib")) ... If I were clever enough I now guess I should be able to unpack the pytables lzo Windows binaries to some suitable place (any recommendations?) and modify the setup.py such that it correctly "binds the dll" (this is black magic to me). One thing, which concerns me, is that a file lzo.lib is mentioned in the current setup.py, but there is not a file with that name in the GnuWin32 zip zip file from Francesc in the lib folder of the zip I do find two lib files.: liblzo.lib liblzo-bcc.lib but are any of these related to the lzo.lib mentioned in the setup.py? It does not help that I have a very poor understanding of how Python binds to native libraries, nor how things should be "installed" manually. My next question, if somehow someone is able to guide me a little in the process, then how do I use the library once available. The README indicates that I should use the internal Python documentation- So I guess i should just open an IPython shell do an import lzo? and then tab on lzo. and see what is available? Sorry for the long post. Kind regards, Kim -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tookit for science and education
Michele Simionato wrote: > My vote is for ipython + matplotlib. Very easy and very powerful. Is it really easier than to use MATLAB(TM)? -James -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tookit for science and education
Robert Kern wrote: > ... Once you move outside of that box and start doing real > programming, Python (with Numeric, ipython, matplotlib, scipy, et al.) > beats MATLAB handily. As one who is really newbie on Python, In MATLAB we can represent the codes for the matrix manipulation as really like mathematical forms, e.g., MATLAB> H = U*D*V' It definitely makes the science programmer easier and faster to write their codes. Moreover, from some recent versions JIT has been included in MATLAB, which speeds up near to C/C++ programs. -James -- http://mail.python.org/mailman/listinfo/python-list
Re: how do i add a new path into sys.path?
Steve Holden wrote: > sys.path.append(r"C:\Temp") In this case, do I need to save the refined path, i.e, the original paths + the new path (r"C:\Temp"), by using some command in order to use it permanently. if yes, it would be greatly appreciated to noitce the correspoding command and the usage of it. -James -- http://mail.python.org/mailman/listinfo/python-list
Re: Well, another try Re: while c = f.read(1)
Robert Kern 쓴 글: > > Now go read the documentation. > Thanks to your comments, I read the corresponding helps searched by Google. (Sorry to say a specific search engine here, but I must say that it is really convinient.) Now I realized that Command 'lambda' is a similar to Command 'inline' in C++. In addition, Command 'iter' is something new but not much new to c engineers, since it is related to 'for loops', e.g., >>> s = 'abc'; it = iter(s); it.next() I would want to express my appreciation to Paul, Robert, Jeremy, Grant, and Bengt, who provide good guidelines to get the answers in newsgroups. -James -- http://mail.python.org/mailman/listinfo/python-list
Re: Considering moving from PowerBuilder to Python
Norm Goertzen wrote: > I'm really only interested in programming for Windows XP. It is warned that the sequal is not directly related to the your question. However, hope that it helps your decision to move from the old stuff to the new stuff. The thing is that as you decideded to change your main programming language, why you don't turn to change your programming environment too. If you start to use Java, no more need to be dependent on one specific os. If you have any interest in my suggestion, please visit Jython (www.jython.org). Declrare that I have no relationship with the developement of Jython. -James Gold -- http://mail.python.org/mailman/listinfo/python-list
Re: Considering moving from PowerBuilder to Python
malv wrote: > As of late, I installed eric3 on linux Suse 9.3 and was happily > surprised to find out that I didn't have to bother with installing Qt, > PyQt, etc. FYI, I installed eric3 on Windows XP. It is one of the nice IDE environments for Python. If I must say some bad point of it, I want to reaveal that there are some mistakes in the editing window based on my experience. -James Gold -- http://mail.python.org/mailman/listinfo/python-list
What are the required modules for ScientificPython?
Hi, all I need "multiarray" package which is required for "ScientificPython". However, I couldn't find multiarray in Python Package index site. Where is this? currently, when executing example script in "Scientific Python", there are importing error for "multiarray" Sincerely, Hyun-Chul Kim Biomatics Lab. Department of BiosystemsKorea Advanced Institute of Science and TechnologyYusung-Gu, Taejon 305-333Republic of Korea -- http://mail.python.org/mailman/listinfo/python-list
What are the required modules for ScientificPython?
Hi, all I need "multiarray" package which is required for "ScientificPython". However, I couldn't find multiarray in Python Package index site. Where is this? currently, when executing example script in "Scientific Python", there are importing error for "multiarray" Sincerely, Hyun-Chul Kim Biomatics Lab. Department of BiosystemsKorea Advanced Institute of Science and TechnologyYusung-Gu, Taejon 305-333Republic of Korea -- http://mail.python.org/mailman/listinfo/python-list
distance, angle restraint
Hi, all I put more than 10,000 points in a box and then want to get one of many solutions that matches all angle restraints among any 3 points and all distance restraints between any 2 points. How can I achieve this? Please recommend any packages or appropriate methods. Thanks in advance, Biomatics Lab. Department of BiosystemsKorea Advanced Institute of Science and TechnologyYusung-Gu, Taejon 305-333Republic of Korea -- http://mail.python.org/mailman/listinfo/python-list
How to import C++ static library?
Hi all, I'm very very beginner of python but I'm dare to ask this question straight away. =P Is it possible to import C++ static library compiled by GCC? The target is definitely Linux machine. I found some examples from Google showing the way C++ can import Python so called embedded python. But I want to the opposite way of this. I want to import (or include in C world terminology) the library which is a blah.a file to reuse in python. Any suggestion or idea for this stupid beginner? ;) cheers, Alex -- http://mail.python.org/mailman/listinfo/python-list