Re: Java Integer.ParseInt translation to python
On Mon, 31 Jan 2005 19:23:35 -0500, jose isaias cabrera <[EMAIL PROTECTED]> wrote: > > Greetings! > > I've looked through the internet (not long, though) but I have not been able > to find a python translation to > > buffer[0] = (byte)Integer.parseInt(string,16); > > Has anyone ported any java programs to python and has translated this? > > any help would be greatly appreciated. > > thanks. > > josé > buffer[0] = int(string, 16) http://docs.python.org/lib/built-in-funcs.html -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you do arrays
On Tue, 01 Feb 2005 10:52:45 -0800, Thomas Bunce <[EMAIL PROTECTED]> wrote: > I am new at Pyton and I am learning from book not classes > so please forgive my being slow > > The below does not work I get an Error of File > "Matrix[index] = k > NameError: name 'iMatrix' is not defined" > > while index < majorlop1: >index = index + 1 >k = random.choice(listvalues) + 1 >iMatrix[index] = k > > The book statement of > array(typecode, initializer) does not make sence > to me how it henerates ore relaes to the org name > for the array. > > Thank You > Tom > -- > http://mail.python.org/mailman/listinfo/python-list > Like any other variable, you need to declare iMatrix before you use it: $ python Python 2.4 (#1, Dec 28 2004, 12:08:51) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import random >>> import array >>> index = 0 >>> majorlop1 = 4 >>> iMatrix = array.array('b') >>> listvalues = [1, 2, 3, 4] >>> while index < majorlop1: ... index = index + 1 ... k = random.choice(listvalues) + 1 ... iMatrix.append(k) ... >>> iMatrix array('b', [3, 5]) >>> You should probably look at the wealth of information at http://www.python.org/doc - the tutorial is a good start on how to use the language, and the library reference has much more depth on the array module. http://docs.python.org/lib/module-array.html -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: python code with indention
On Wed, 09 Feb 2005 10:10:29 -0800 (PST), Xah Lee <[EMAIL PROTECTED]> wrote: > i thought it is trivial for the Python parser to spit out a version > with matching brackets. Similarly, perhaps some opensourcing student > has modified a parser to read in a matching brackets delimited version > of Python. > > Xah > [EMAIL PROTECTED] > http://xahlee.org/PageTwo_dir/more.html > Well, there's always the pindent.py script. Get the python source, and look at Tools/scripts/pindent.py This isn't an alternate parser, but it can turn a python script with end-block comments and no indentation into a correctly indented python script. -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Need direction to kill a virus
On Wed, 2 Mar 2005 17:46:44 -0800, James Stroud <[EMAIL PROTECTED]> wrote: > Four steps, meant to help, really. > > 1. shut down your computer > 2. erase your hard drive > 3. install linux with a firewall > 4. reboot > > You can always run your beloved window$ under vmware. > > Alternately, get a Mac. > > You will never have another problem like this again. The real virus is your > operating system. > > Sorry for the brutally honest and yet ultimately helpful answer. If it angers > you as it does some, well, then you may actually deserve what you get. > > James > > (Living M$ free for 7 years and never been happier.) > > Based on the mailing lists I've found your name on and the messages there, I'm going to give you the benefit of the doubt and assume that shouting "Don't use windows!" in your general direction would be just beating a dead horse. Unfortunately, I don't know of an easy way to remove unidentified viruses from an already-infected computer. I really doubt there is a five-minute guru answer, and unless you find such a solution, you will probably have to resort to the reformat/reinstall route. You mention that you have already reinstalled, but do not make clear whether or not you reformatted your hard drive first - if the problem is in a file not overwritten by the windows install, it could easily survive a reinstall without a reformat. Short of switching to a different operating system, there are a few steps I can recommend to help defend against malicious attachments and such: 1) Never, ever, ever use Outlook. Outlook Express is almost-but-not-quite as bad. Microsoft made several design decisions to "enhance" the user experience which have resulted in pretty much every email virus and worm, ever. As an email client for people used to Outlook Express, I heartily reccomend Mozilla Thunderbird (http://www.mozilla.org/products/thunderbird/). 2) Use a good spamfilter to automate the process of sorting out junk from your mail. After a little training, the Bayesian filter built-in to Thunderbird works well enough for my purposes. 3) If you must use windows, firewalling and virus scanning are essential. You seem to already have that part, plus a certain paranoia about attachments that puts you well ahead of the curve. 4) Similar to #1, you should NEVER surf the web in Internet Explorer. Again, this is primarily because Microsoft chose to include features (ActiveX controls in web pages) that have led to an unmanagable number of security problems. Firefox (http://www.getfirefox.com) is a wonderful alternative browser for Windows users, and will be available to you on other platforms if you ever choose to switch to an OS less beleagured by viruses, trojans, and spyware. 5) You seem appropriately paranoid about attachments, although I do have to wonder what kind of message was sent to you that made yo uwant to open "details.txt" in the first place. I think you will appreciate an email client that shows you the file type and asks for confirmation before launching an attachment, just like you might appreciate a web browser that shows the file type and asks for confirmation before launching a downloaded file. 6) With the filename you gave, it shouldn't be that hard to find some notes on this virus with google. 7) When the system is running away with background processes like you describe, use the task manager to find out which process is using the resources. Use this information in your research for a fix. -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python docs [was: function with a state]
On 8 Mar 2005 17:07:31 -0800, Xah Lee <[EMAIL PROTECTED]> wrote: > thanks for the help... > > --- > the python doc is stilted. It tried to organized the thing and with a > style around some highbrow inane "computer science" outlook. > > i found the little section on global > (http://python.org/doc/2.4/ref/global.html) > and can't make out what shit it is trying to say without having read > and figured out the entire doc of its style and contexts and > definitions. (formalization varies and computing model and jargons mean > different things.) > > Python doc writers needs to re-organize and re-style their docs so that > its organization is towards programing, as opposed to how the > implementation works (as in the Lib Reference), or a formalization of > the language spec. (e.g. the fucking semi-joke of "(for language > lawyers)" and BNF and those Runtime "Service" shits.) Its style > needs to shift from highbrowism to pragmatic and exemplary. > > I've addressed some of the jargon-riding ills common in industry with > examples from the Python doc, archived here: > http://xahlee.org/Periodic_dosage_dir/t2/xlali_skami_cukta.html > > as to the way of its stiltedenss and academicism, which make it hard > for programers to find or apply any info, i'll expound later. > > PS just so that there is no misunderstanding: The docs of unix and > Perl, are fucking criminally incompetent. Python docs, although stilted > in a academic way, but nevertheless is solid, and its writers are > educated, and tried best to make it a quality one, albeit sometimes > inevitably showed some masterbation and jargonization. While the unix > and Perl docs, (and essentially all things out of unix, e.g. Apache > docs), are fucking incompetent drivels and in many cases exorbitant > lies, and they semi-present it as humor and want and brainwash people > to take them as norm. In a nutshell, these people are spreading > untruths and indirectly are causing massive harm in the computing > industry. People, we need to stop it. This each of us can do by not > accepting their attitudes or behavior. In online forums, work place, > conventions, conversations etc., raise questions or otherwise voice > your opinion whenever you can. > > Xah > [EMAIL PROTECTED] > http://xahlee.org/PageTwo_dir/more.html > > -- > http://mail.python.org/mailman/listinfo/python-list > Have you submitted a patch? I'm curious how you would document "global". -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Good use for Jython
On 15 Mar 2005 23:54:16 -0800, Mike Wimpe <[EMAIL PROTECTED]> wrote: > Other than being used to wrap Java classes, what other real use is > there for Jython being that Python has many other GUI toolkits > available? Also, these toolkits like Tkinter are so much better for > client usage (and faster) than Swing, so what would be the advantage > for using Jython? or Is Jython really just so that Java developers can > write Java code faster? > > Mike Wimpe > > -- > http://mail.python.org/mailman/listinfo/python-list > I use an embedded Jython interpreter extensively for the business logic layer of a Servlet/J2ee application. The back end uses, Hibernate to connect to the database, so Jython's JavaBean functionality is very useful for me, vastly simplifying and clarifying my own logic. As an added bonus, it is vastly easier to debug and redeploy a Jython script file into a running system than it is to do the same with a session EJB. -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Jython performance
On Wed, 22 Dec 2004 17:03:55 -0200, Gabriel Cosentino de Barros <[EMAIL PROTECTED]> wrote: > > > On the "Best GUI for small-scale accounting app?" tread some people > mentioned jython. I went to read about it, but i was wondering if anyone has > any real project done with it and can give real world comments about > performance. > > Thanks, > Gabriel > -- > http://mail.python.org/mailman/listinfo/python-list > > I've been very happy with it's performance, after the one-time interpreter startup. Currently, I am using Jython embedded in a large Web Application, with Struts actions defined in Jython working with Java Beans managed by a Hibernate back end. The Jython-beans interoperability makes this very simple, and I'm not seeing an appreciable performance difference between the Jython actions and the pure Java actions. -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question
On 28 Mar 2005 15:00:37 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > How do i create two memory mapped buffers(mmap) and pass an index to > select which one needs to be populated? > > Is it possible to define the size of the buffer? > > -SB > > -- > http://mail.python.org/mailman/listinfo/python-list > http://docs.python.org/lib/module-mmap.html I haven't tried it, but it should be pretty straightforward to create two mmaped buffers. Step 1: Import the mmap module. Step 2: Create or find the file you want to map. Open it, and get the fileno. Call mmap.mmap, passing the fileno and buffer size. Repeat Step 2 with a different file to create a second mmaped buffer. I'm not sure what you mean by "and pass an index to select which one needs to be populated". If you pack the buffers into a tuple/list/other sequence object, it should be easy to access them by index: >>> buffers = (buffer_1, buffer_2) >>> do_something_to(buffers[0]) >>> do_something_else_with(buffers[1]) To mmap buffers, you MUST define the size. I'm sorry I can't be more helpful; perhaps if you gave a higher-level description of what you are trying to accomplish, I could give better pointers in the right direction. -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: doing "checksum" in python
On 28 Mar 2005 15:11:32 -0800, GujuBoy <[EMAIL PROTECTED]> wrote: > is there a built-in function that does a "checksum" on a file...basicly > counts the bytes and computes a 16-bit checksum for each given FILE. > > this is the like the "sum" command in unix > > -- > http://mail.python.org/mailman/listinfo/python-list > Not built-in, but you can find a few implementations with a quick google search for "python 16-bit checksum": http://mail.python.org/pipermail/python-list/2001-May/042691.html http://mail.python.org/pipermail/python-list/2004-January/204983.html http://mail.python.org/pipermail/python-list/2004-January/204998.html -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: initialize a dictionary
On 30 Mar 2005 13:02:05 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > Can I do something like this? > > table = {} > table[32, 16] = 0x0 > > Where 32 specifies rows and 16 specifies columns and i am trying to > initialize it to zero > > I should be able to do comparisons like: > table[t1, t2] == 0x1 etc. > -SB > Try it. It works. Sort of. This code actually creates a dict named "table" mapping the key tuple (32, 16) to the value 0x0. Note that you are NOT creating a two-dimensional array, so this approach may be problematic if you ever need to iterate values "by row" or "by column". There is a python F.A.Q. on this, which you may find useful: http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: within a class, redefining self with pickled file
On 7 Apr 2005 15:27:06 -0700, syd <[EMAIL PROTECTED]> wrote: > def unpickle(self): > self = pickle.load(open(self.getFilePath('pickle'))) > > This evidently does not work. Any idea why? I'd like to be able to > replace a lightly populated class (enough to identify the pickled > version correctly) with it's full version that's sitting pickled in a > file. > > As of right now, I need to just return self and redefine the class. > > Thanks! > > -- > http://mail.python.org/mailman/listinfo/python-list > This problem has nothing to do with pickling. In general, assigning to a parameter (even self) will not make a change that lasts after the method call. For example: >>> class A: ... def change(self): ... self = "something else entirely" ... >>> a = A() >>> a.change() >>> a <__main__.A instance at 0x009DCD00> Note, however, that you can MODIFY self in-place within a method. You can probably hack together a solution that modifies self.__dict__, self.__class__, self.__class__.__dict__, or some other magic properties. -- Sean Blakey Saint of Mild Amusement, Evil Genius, Big Geek Python/Java/C++/C(Unix/Windows/Palm/Web) developer quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0]) -- http://mail.python.org/mailman/listinfo/python-list