An array of a "list" of names.

2005-03-13 Thread spencer
Hi, I'm using NumPy to build an array of a list of names that will be of multiple dimensions.I did do a google on this subject, but couldn't find what I was looking for. The problem I'm having is there are space between each character in each name. To fix this I used the attribute 'tostring'. Thi

why this error?

2005-03-15 Thread spencer
Hi, I'm not sure why I can't concatenate dirname() with basename(). Traceback (most recent call last): File "showDir.py", line 50, in ? print 'somthing new...', os.path.join(os.path.dirname(os.getcwd)) + os.path.basename(os.getcwd()) File "/usr/lib/python2.3/posixpath.py", line 119, in dir

A Q. on pop().

2005-03-17 Thread spencer
Hi, The code. def buildStackMajor(): for node in dirStackMinor: #print 's is the node...', node dirStackMajor.append(node) dirStackMinor.pop() print 'POP the stack...', len(dirStackMinor) print 'after pop...', dirStackMinor When I start the "for" loop I

How to run python without python

2010-04-01 Thread Spencer
Is there a way to developing a script on linux and give it to someone on microsoft, so that they could run it on microsoft without installing python? Wayne -- http://mail.python.org/mailman/listinfo/python-list

Instances' __setitem__ methods

2011-06-20 Thread Spencer Pearson
I was recently trying to implement a dict-like object which would do some fancy stuff when it was modified, and found that overriding the __setitem__ method of an instance did not act the way I expected. The help documentation (from help(dict.__setitem__)) claims that "d.__setitem__(k,v)" is equiva

Add a method to list the current named logging levels

2021-09-02 Thread Edward Spencer
t be accessed because they change (and in fact, between python 2 and 3, they did). Any thoughts? Thanks, Ed Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: Add a method to list the current named logging levels

2022-03-30 Thread Edward Spencer
在 2021年9月3日星期五 UTC+1 18:50:51, 写道: > > On 2 Sep 2021, at 23:38, Dieter Maurer wrote: > > > > Edward Spencer wrote at 2021-9-2 10:02 -0700: > >> Sometimes I like to pass the logging level up to the command line params > >> so my user can specific what level

Re: Add a method to list the current named logging levels

2022-03-30 Thread Edward Spencer
在 2022年3月30日星期三 UTC+1 16:38:26, 写道: > > On 30 Mar 2022, at 16:11, Edward Spencer wrote: > > > > 在 2021年9月3日星期五 UTC+1 18:50:51, 写道: > >>>> On 2 Sep 2021, at 23:38, Dieter Maurer wrote: > >>> > >>> Edward Spencer wrote at 2021-9-2

Multiple problems with Python 3.7 under Windows 7 Home Premium

2018-09-21 Thread Spencer Graves
/ remove programs."   I repeated "Windows App Certification Kit", except that this time when the "Modify setup" window appeared, I clicked "repair". It came to that same point and gave the same error.   Suggestion?   Thanks,   Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: Multiple problems with Python 3.7 under Windows 7 Home Premium

2018-09-22 Thread Spencer Graves
udio in" on my Windows 7 machine.   Thanks again.   Spencer Graves On 2018-09-21 23:33, Terry Reedy wrote: On 9/21/2018 8:57 PM, MRAB wrote: On 2018-09-22 01:02, Michael Torrie wrote: On 09/21/2018 07:22 AM, Spencer Graves wrote: PYTHON - M PIP INSTALL PYAUDIO    &qu

Problems installing RStudio from Anaconda Navigator

2018-10-11 Thread Spencer Graves
ments tab create a new R/Python3.5 environment", then install RStudio into that new environment.[1]   So I killed the RStudio install and looked at the "Environments tab".  I'm new to Anaconda Navigator, and I didn't know what I was looking at so decided to ask here.  

Re: Overwhelmed by the Simplicity of Python. Any Recommendation?

2018-10-12 Thread Spencer Graves
tarted with them after two days of effort.   2.  Find a reasonable "Introduction to Python" on the web. Others on this list should be able to suggest several.  I just found "https://docs.python.org/2/tutorial/introduction.html".  A web search for "an introduction to

Package creation documentation?

2018-10-16 Thread Spencer Graves
ot; for this, and what I should do after that?   I have decades of coding experience, but only a small portion of that was with Python, and that was roughly 7 years ago.   Thanks,   Spencer Graves [1] https://docs.python.org/3/glossary.html#term-package [2] https://packaging.pyth

Wikipedia on Python

2018-10-16 Thread Spencer Graves
fit lots of people.   If you have suggestions for how the article might be improved, you can post them to the "Talk" page associated with that article or send them to me.  If you are "autoconfirmed" with the Wikimedia system, you can make the changes your

Mixing R and Python in the same Jupyter Notebook and finding Python code within an RMarkdown document

2018-11-02 Thread Spencer Graves
R snippet, which does what I want (namely recording 5 seconds of whatever is connected to "audio in" or something similar on your computer and writing it to "KKFI2018-10-12t13_16-5sec.wav".   Thanks,   Spencer Graves -- https://mail.python.org/mailman/listinfo/python-list

Re: Good editor for python

2018-11-11 Thread Spencer Graves
do this also, but I've not tried or verified them.   Spencer Graves On 2018-11-11 08:11, Andrew Z wrote: If you do scripts - emacs/vi is the way to go. If you need something more (like creating libraries, classes) go with pycharm. It is a professionally made IDE. Over past 2 years

Re: sampling from frequency distribution / histogram without replacement

2019-01-14 Thread Spencer Graves
been used extensively.  You'd have to work really hard to do better, in my judgment.       Spencer Graves DISCLAIMER:  I'm primarily an R guy and only use Python when I can't find a sensible way to do what I want in R. Duncan -- https://mail.python.org/mailman/listinfo/python-list

Re: 3 random numbers

2019-01-14 Thread Spencer Graves
i + 1   This sounds like a homework problem for a class.  I don't know how this list treats such questions, but I suspect answering such questions may be discouraged.   Hint:  Read the documentation on "while" and then trace the iterations.       Spencer -- ht

Re: Your IDE's?

2019-03-25 Thread Spencer Graves
.com" is a URL being advertised for sale for $150,000.  "ping something.com" returns, "cannot resolve something.com:  Unknown host".   Clearly the original poster is playing games with us.       Spencer Cheers, Gene Heskett -- https://mail.python.org/mailman/listinfo/python-list

How to create a list and append to list inside a mqtt and GUI program?

2019-09-01 Thread Spencer Du
Hi I have code for GUI and MQTT. In GUI.py I have "def loadGUI" which loads up a GUI file if the file exists in current directory. I want to add the file name to a list when a file is imported and for each subsequent file that is imported I want the file name to be imported to the same list an

Hi how do I import files inside a txt file?

2019-09-02 Thread Spencer Du
,test2 Each name refers to a python file. Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: Hi how do I import files inside a txt file?

2019-09-02 Thread Spencer Du
On Monday, 2 September 2019 13:36:06 UTC+2, Pankaj Jangid wrote: > Spencer Du writes: > > > How do i import files inside a txt file if they exist in the current > > directory? > > > > Here is the current code but I dont know how to do it correctly. > >

Re: Hi how do I import files inside a txt file?

2019-09-02 Thread Spencer Du
On Monday, 2 September 2019 13:36:06 UTC+2, Pankaj Jangid wrote: > Spencer Du writes: > > > How do i import files inside a txt file if they exist in the current > > directory? > > > > Here is the current code but I dont know how to do it correctly. > >

Re: Hi how do I import files inside a txt file?

2019-09-02 Thread Spencer Du
On Monday, 2 September 2019 15:03:52 UTC+2, Joel Goldstick wrote: > On Mon, Sep 2, 2019 at 8:46 AM Spencer Du wrote: > > > > On Monday, 2 September 2019 13:36:06 UTC+2, Pankaj Jangid wrote: > > > Spencer Du writes: > > > > > > > How do i import

Re: Hi how do I import files inside a txt file?

2019-09-02 Thread Spencer Du
On Monday, 2 September 2019 15:29:07 UTC+2, Joel Goldstick wrote: > On Mon, Sep 2, 2019 at 9:21 AM Spencer Du wrote: > > > > On Monday, 2 September 2019 15:03:52 UTC+2, Joel Goldstick wrote: > > > On Mon, Sep 2, 2019 at 8:46 AM Spencer Du wrote: > > > > &g

Help needed urgently for running some code!!!!

2019-09-02 Thread Spencer Du
Hi I want to execute "from devicesEmbedded import *": in GUI.py after all code in GUI.py is run. Also how do I make the devicesEmbedded.py reload and run when a txt file is created in the name of "list_of_devices.txt" in the GUI.py python program. GUI.py import logging from datetime import

Help needed to run some code!!!!

2019-09-02 Thread Spencer Du
ded.py to execute after GUI.py has executed first. Thanks Spencer GUI.py import logging from datetime import timedelta import time from thespian.actors import * from transitions import Machine import paho.mqtt.client as mqtt import importlib import os import os.path import sys from

How to remove a string from a txt file?

2019-09-04 Thread Spencer Du
Hi I want to remove a string from a txt file and then print out what I have removed. How do I do this. The txt file is in this format and should be kept in this format. txt.txt: laser,cameras, Thanks -- https://mail.python.org/mailman/listinfo/python-list

Help me fix a problem

2019-09-06 Thread Spencer Du
ibed to topic") def on_message(client, userdata, msg): print("message recieved= " + msg.payload.decode()) # print("File which you want to import(with .py extension)") print("message topic=", msg.topic) print("message qos="

Re: Help me fix a problem

2019-09-06 Thread Spencer Du
On Friday, 6 September 2019 20:15:40 UTC+2, MRAB wrote: > On 2019-09-06 18:11, Spencer Du wrote: > > Hi > > > > I want to print yes in gui.py but it does not get printed because of the > > json. How do I fix this. Execute embedded.py and then gui.py to test. >

Re: Help me fix a problem

2019-09-06 Thread Spencer Du
On Friday, 6 September 2019 20:15:40 UTC+2, MRAB wrote: > On 2019-09-06 18:11, Spencer Du wrote: > > Hi > > > > I want to print yes in gui.py but it does not get printed because of the > > json. How do I fix this. Execute embedded.py and then gui.py to test. >

Re: Help me fix a problem

2019-09-06 Thread Spencer Du
On Friday, 6 September 2019 20:15:40 UTC+2, MRAB wrote: > On 2019-09-06 18:11, Spencer Du wrote: > > Hi > > > > I want to print yes in gui.py but it does not get printed because of the > > json. How do I fix this. Execute embedded.py and then gui.py to test. >

Why is "Subscribing to topic topic/test" printed in console log before connect message?

2019-09-10 Thread Spencer Du
nt, userdata, msg): if msg.payload.decode() == "Hello world!": print("Yes!") Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: TechRepublicDEVELOPERCXO JPMorgan's Athena has 35 million lines of Python code, and won't be updated to Python 3 in time

2019-09-15 Thread Spencer Graves
nceptually and practically the same kind of thing.   Spencer Graves Cheers, Gene Heskett -- https://mail.python.org/mailman/listinfo/python-list

How to publish a message of the qspinbox value when the qspinbox sets the slider with corresponding value.

2019-09-26 Thread Spencer Du
Hi How do I publish a message of the qspinbox value when the qspinbox sets the slider with corresponding value. Thanks # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'laser.ui' # # Created by: PyQt5 UI code generator 5.13.0 # # WARNING! All changes made in this fi

How to publish a message of the qspinbox value when the qspinbox sets the slider with corresponding value.

2019-09-27 Thread Spencer Du
tton_7.setText(_translate("Laser", "ON")) self.label.setText(_translate("Laser", "445nm")) self.label_2.setText(_translate("Laser", "488nm")) self.label_3.setText(_translate("Laser", "515nm"))

How to publish a message of the qspinbox value when the qspinbox sets the slider with corresponding value.

2019-09-27 Thread Spencer Du
label_3.setText(_translate("Laser", "515nm")) self.label_4.setText(_translate("Laser", "561nm")) self.label_5.setText(_translate("Laser", "594nm")) self.label_6.setText(_translate("Laser", "638nm")) self.label_7.setText(_translate("Laser", "LED")) self.pushButton_8.setText(_translate("Laser", "ON")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Laser = QtWidgets.QMainWindow() ui = Ui_Laser() ui.setupUi(Laser) Laser.show() sys.exit(app.exec_()) laserEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference class Laser(Actor): async def handle_message(self, message: Message): print("Laser") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a laser!" +"\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Laser() as laser: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(laser, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) Regards Spencer -- https://mail.python.org/mailman/listinfo/python-list

How to publish a message of the qspinbox value when the qspinbox sets the slider with corresponding value.

2019-09-27 Thread Spencer Du
label_3.setText(_translate("Laser", "515nm")) self.label_4.setText(_translate("Laser", "561nm")) self.label_5.setText(_translate("Laser", "594nm")) self.label_6.setText(_translate("Laser", "638nm")) self.label_7.setText(_translate("Laser", "LED")) self.pushButton_8.setText(_translate("Laser", "ON")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Laser = QtWidgets.QMainWindow() ui = Ui_Laser() ui.setupUi(Laser) Laser.show() sys.exit(app.exec_()) laserEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference class Laser(Actor): async def handle_message(self, message: Message): print("Laser") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a laser!" +"\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Laser() as laser: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(laser, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) Regards Spencer -- https://mail.python.org/mailman/listinfo/python-list

How to publish a message of the qspinbox value when the qspinbox sets the slider with corresponding value.

2019-09-27 Thread Spencer Du
label_3.setText(_translate("Laser", "515nm")) self.label_4.setText(_translate("Laser", "561nm")) self.label_5.setText(_translate("Laser", "594nm")) self.label_6.setText(_translate("Laser", "638nm")) self.label_7.setText(_translate("Laser", "LED")) self.pushButton_8.setText(_translate("Laser", "ON")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Laser = QtWidgets.QMainWindow() ui = Ui_Laser() ui.setupUi(Laser) Laser.show() sys.exit(app.exec_()) laserEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference class Laser(Actor): async def handle_message(self, message: Message): print("Laser") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a laser!" +"\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Laser() as laser: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(laser, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) Regards Spencer -- https://mail.python.org/mailman/listinfo/python-list

How can I set the value of the textedit box and slider of ui with the value from a config file when it has been created?

2019-10-01 Thread Spencer Du
27;, 'intensity')) # if self.textbox.text() == "": # self.mySlider.setValue(0) # else: # self.mySlider.setValue(config.get('445nm', 'intensity')) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) config.py [445nm] intensity = 4 Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

How execute at least two python files at once when imported?

2019-11-05 Thread Spencer Du
sed") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a stage!" + "\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Stages() as stages: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(stages, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Spencer Du
On Wednesday, 6 November 2019 09:05:42 UTC+1, Christian Gollwitzer wrote: > Am 06.11.19 um 03:59 schrieb Dennis Lee Bieber: > > On Tue, 5 Nov 2019 10:33:20 -0800 (PST), Spencer Du > > declaimed the following: > > > >> Hi > >> > >> I want t

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Spencer Du
On Tuesday, 5 November 2019 19:37:32 UTC+1, Karsten Hilbert wrote: > > I want to execute at least two python files at once when imported but I > > dont know how to do this. > > Currently I can only import each file one after another but what i want is > > each file to be imported > > at the same

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Spencer Du
On Tuesday, 5 November 2019 21:05:02 UTC+1, Terry Reedy wrote: > On 11/5/2019 1:33 PM, Spencer Du wrote: > > > I want to execute at least two python files at once when imported but I > > dont know how to do this. Currently I can only import each file one after > > an

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Spencer Du
On Tuesday, 5 November 2019 19:41:59 UTC+1, Bob Gailer wrote: > On Nov 5, 2019 1:35 PM, "Spencer Du" wrote: > > > > Hi > > > > I want to execute at least two python files at once when imported but I > dont know how to do this. Currently I can only import

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Spencer Du
On Tuesday, 5 November 2019 19:44:46 UTC+1, Rhodri James wrote: > On 05/11/2019 18:33, Spencer Du wrote: > > I want to execute at least two python files at once when imported but > > I dont know how to do this. Currently I can only import each file one > > after another bu

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Spencer Du
Why is importing modules in parallel bad? Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Spencer Du
Hi Sorry if I haven't stated my requirements clearly. I just wanted a way to import at least two python files in parallel and I wanted to know how this can be done or a reason why its bad as stated in another post. Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: What is "self"?

2005-09-23 Thread Michael Spencer
Ron Adam wrote: > Erik Max Francis wrote: > >>Ron Adam wrote: >> >> >>>When you call a method of an instance, Python translates it to... >>> >>> leader.set_name(leader, "John") >> >> >>It actually translates it to >> >>Person.set_name(leader, "John") >> > > > I thought that I might have

Re: Wrapping classes

2005-09-23 Thread Michael Spencer
Jeremy Sanders wrote: > Colin J. Williams wrote: > > >>Could you not have functions a and b each of which returns a NumArray >>instance? >> >>Your expression would then be something like a(..)+2*b(..). > > > The user enters the expression (yes - I'm aware of the possible security > issues), as

Re: What is "self"?

2005-09-27 Thread Michael Spencer
Ron Adam wrote: > What I've noticed is you can block the visibility of a class attribute, > which include methods, by inserting an object in the instance with the > same name. > [snip example of this behavior] Yes, that's true for "non-data descriptors" (see last two bullets below) Raymond Het

Re: Silly function call lookup stuff?

2005-09-27 Thread Michael Spencer
Lucas Lemmens wrote: > Dear pythonians, > > I've been reading/thinking about the famous function call speedup > trick where you use a function in the local context to represent > a "remoter" function to speed up the 'function lookup'. > > "This is especially usefull in a loop where you call the

Re: grouping array

2005-09-29 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > hi if I have an array > > say x = [[2,2,0,0,1,1], > [1,1,0,0,1,1], > [1,1,0,0,1,1]] > I basically want to group regions that are non zero like I want to get > the coordinates of non zero regions..as (x1,y1,x2,y2) > [(0,0,2,1),(0,4,2,5)] which show the t

Re: grouping array

2005-09-30 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > fredrick's solutions seems to be more closer to what I was looking > for.But I am still not sure if that could be done without the use of > Image module. What do you mean by "closer to what I was looking for"? For the single test case you provided: > say x = [[2,2,0,0

Re: Feature Proposal: Sequence .join method

2005-09-30 Thread Michael Spencer
Terry Reedy wrote: > "David Murmann" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>>def join(sep, seq): >>>return reduce(lambda x, y: x + sep + y, seq, type(sep)()) >> >>damn, i wanted too much. Proper implementation: >> >>def join(sep, seq): >>if len(seq): >>r

Re: SPE IDE for Python

2005-11-08 Thread Chris Spencer
py wrote: > Anyone here use SPE (http://www.stani.be/python/spe/blog/). ...the IDE? > > Also, anyone know if it supports CVS or has a plugin for CVS? If not, > what do you use to get your code into CVS (via an IDE preferably)? I used to use SPE quite frequently, until it went nearly unmaintained

Re: Recompile AST?

2005-11-10 Thread Chris Spencer
Leif K-Brooks wrote: > [EMAIL PROTECTED] wrote: > >>Is it possible to recompile the AST generated by compiler.parse, back >>into code or an executable code object? > > > Into a bytecode object: > > >>> from compiler.pycodegen import ModuleCodeGenerator > >>> from compiler.misc import set_file

Re: Dynamically Update Class Definitions?

2005-11-11 Thread Chris Spencer
Alex Martelli wrote: > <[EMAIL PROTECTED]> wrote: > > >>Is there a way to loop through all instantiated objects and update >>their classes when a source file changes? I know about Michael Hudson's >>method >>(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164), but >>you have to modif

Re: Dynamically Update Class Definitions?

2005-11-11 Thread Chris Spencer
Chris Spencer wrote: > Alex Martelli wrote: >> If you're in no hurry, you COULD loop over all of gc.get_objects(), >> identify all those which are instances of old_class and "somehow" change >> their classes to new_class -- of course, x.__class__ = new_cla

Re: Dynamically Update Class Definitions?

2005-11-12 Thread Chris Spencer
Jean-Paul Calderone wrote: > There are lots of cases where you cannot rebind the __class__ > attribute. For a comprehensive treatment of this idea (but still not a > completely functionality implementation), take a look at >

Re: Need advice on subclassing code

2005-11-15 Thread Michael Spencer
Kent Johnson wrote: > Rusty Shackleford wrote: >> ... >> C_1_1 and C_1_2 share a common C ancestor, and in practice may be >> identical, but theoretically, could have the same function name with two >> different implementations underneath. >> >> ... > > How are you instantiating the correct class?

Re: best cumulative sum

2005-11-22 Thread Michael Spencer
David Isaac wrote: for a solution when these are available. > Something like: > def cumreduce(func, seq, init = None): > """Return list of cumulative reductions. > > This can be written more concisely as a generator: >>> import operator >>> def ireduce(func, iterable, init): ...

Re: aligning a set of word substrings to sentence

2005-12-01 Thread Michael Spencer
Steven Bethard wrote: > I've got a list of word substrings (the "tokens") which I need to align > to a string of text (the "sentence"). The sentence is basically the > concatenation of the token list, with spaces sometimes inserted beetween > tokens. I need to determine the start and end offse

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Michael Spencer
Brendan wrote: ... > > class Things(Object): > def __init__(self, x, y, z): > #assert that x, y, and z have the same length > > But I can't figure out a _simple_ way to check the arguments have the > same length, since len(scalar) throws an exception. The only ways > around this I've

Re: Documentation suggestions

2005-12-06 Thread Michael Spencer
A.M. Kuchling wrote: > Here are some thoughts on reorganizing Python's documentation, with > one big suggestion. > Thanks for raising this topic, and for your on-going efforts in this field. I use the compiled html help file provided by PythonWin, which includes all the core documentation. I u

Re: i=2; lst=[i**=2 while i<1000]

2005-12-06 Thread Michael Spencer
Daniel Schüle wrote: > Hello NG, > > I am wondering if there were proposals or previous disscussions in this > NG considering using 'while' in comprehension lists > > # pseudo code > i=2 > lst=[i**=2 while i<1000] > You are actually describing two features that list comps don't natively suppor

Re: Documentation suggestions

2005-12-07 Thread Michael Spencer
A.M. Kuchling wrote: > On Tue, 06 Dec 2005 10:29:33 -0800, > Michael Spencer <[EMAIL PROTECTED]> wrote: >> not that helpful. "Miscellaneous Services", in particular, gives no clue to >> treasures it contains. I would prefer, for example, to see the data

Re: Bitching about the documentation...

2005-12-07 Thread Michael Spencer
Fredrik Lundh wrote: > Rocco Moretti wrote: > >> Insert punctuation & capitalization to make the following a correct and >> coherent (if not a little tourtured). >> >> fred where guido had had had had had had had had had had had a better >> effect on the reader > > punctuation, including quote ma

Re: newby question: Splitting a string - separator

2005-12-08 Thread Michael Spencer
Thomas Liesner wrote: > Hi all, > > i am having a textfile which contains a single string with names. > I want to split this string into its records an put them into a list. > In "normal" cases i would do something like: > >> #!/usr/bin/python >> inp = open("file") >> data = inp.read() >> names =

Re: Dynamically add Class to Modules

2005-12-08 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > I'm trying to add a class to a module at runtime. I've seen examples > of adding a method to a class, but I haven't been able to suit it to my > needs. > > As part of a testsuite, I have a main process X that searches > recursively for python test files. Those files ty

Re: Dynamically add Class to Modules

2005-12-08 Thread Michael Spencer
[EMAIL PROTECTED] wrote: ... > exec testModule.TheTestCode %(testModule.TheTestName, testModule.TheTestName ) ... Try changing that to exec ~ in testModule.__dict__ otherwise, your class statement gets executed in the current scope Michael -- http://mail.python.org/mailman/listinfo/python-lis

Re: getting host and path from url

2005-12-09 Thread Michael Spencer
Steve Young wrote: > Hi, this is probably an easy question but is there a way to get the host and > path seperatly out of an url? > > Example: > > url = http://news.yahoo.com/fc/world/iraq > > and i want some way of getting: > > host = http://news.yahoo.com > and > path =

Re: newby question: Splitting a string - separator

2005-12-09 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Thomas Liesner wrote: >> Hi all, >> >> i am having a textfile which contains a single string with names. >> I want to split this string into its records an put them into a list. >> In "normal" cases i would do something like: >> >>> #!/usr/bin/python >>> inp = open("file"

args (was Re: Lambda as declarative idiom (was RE: what is lambda used for in real code?))

2005-01-04 Thread Michael Spencer
Roman Suzi wrote: Maybe this is too outlandish, but I see lambdas as a "quote" mechanism, which presents a possibility to postpone (precisely control, delegate) evaluation. That is, an ovehead for lambda must be much lower but at the same time visible to the programmer: d = a + (lambda x, y: x+ y)

Re: pure python code to do modular-arithmetic unit conversions?

2005-01-21 Thread Michael Spencer
Dan Stromberg wrote: Is there already a pure python module that can do modular-arithmetic unit conversions, like converting a huge number of seconds into months, weeks... or a bandwidth measure into megabits/s or gigabits/s or megabytes/s or gigabytes/s, whatever's the most useful (ala df -h)? Than

Re: Reload Tricks

2005-01-21 Thread Michael Spencer
Kamilche wrote: I want my program to be able to reload its code dynamically. I have a large hierarchy of objects in memory. The inheritance hierarchy of these objects are scattered over several files. I find that after reloading the appropriate files, and overwriting the __class__ of object instanc

Re: Reload Tricks

2005-01-22 Thread Michael Spencer
Kamilche wrote: I want my program to be able to reload its code dynamically. I have a large hierarchy of objects in memory. The inheritance hierarchy of these objects are scattered over several files. Michael Spencer wrote: An alternative approach (with some pros and cons) is to modify the class

Re: default value in a list

2005-01-22 Thread Michael Spencer
Alex Martelli wrote: [explanation and the following code:] >>> a, b, c = it.islice( ... it.chain( ... line.split(':'), ... it.repeat(some_default), ... ), ... 3) ... ... >>> def pad_with_default(N, iter

Re: What YAML engine do you use?

2005-01-22 Thread Michael Spencer
Paul Rubin wrote: YAML looks to me to be completely insane, even compared to Python lists. I think it would be great if the Python library exposed an interface for parsing constant list and dict expressions, e.g.: [1, 2, 'Joe Smith', 8237972883334L, # comment {'Favorite fruits': ['apple

Re: What YAML engine do you use?

2005-01-24 Thread Michael Spencer
Fredrik Lundh wrote: Sion Arrowsmith wrote: I'm probably not thinking deviously enough here, but how are you going to exploit an eval() which has very tightly controlled globals and locals (eg. eval(x, {"__builtins__": None}, {}) ? try this: eval("'*'*100*2*2*2*2*2*2*2*2*2") I updated the s

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Michael Spencer
Francis Girard wrote: The following implementation is even more speaking as it makes self-evident and almost mechanical how to translate algorithms that run after their tail from recursion to "tee" usage : Thanks, Francis and Jeff for raising a fascinating topic. I've enjoyed trying to get my

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Michael Spencer
Nick Craig-Wood wrote: Steven Bethard <[EMAIL PROTECTED]> wrote: Nick Craig-Wood wrote: Thinking about this some more leads me to believe a general purpose imerge taking any number of arguments will look neater, eg def imerge(*generators): values = [ g.next() for g in generators ] while True:

Re: limited python virtual machine (WAS: Another scripting language implemented into Python itself?)

2005-01-25 Thread Michael Spencer
Steven Bethard wrote: > > I wish there was a way to, say, exec something with no builtins and with > import disabled, so you would have to specify all the available > bindings, e.g.: > > exec user_code in dict(ClassA=ClassA, ClassB=ClassB) > > but I suspect that even this wouldn't really

Re: limited python virtual machine (WAS: Another scripting language implemented into Python itself?)

2005-01-25 Thread Michael Spencer
Steven Bethard wrote: > > I wish there was a way to, say, exec something with no builtins and > with import disabled, so you would have to specify all the available > bindings, e.g.: > > exec user_code in dict(ClassA=ClassA, ClassB=ClassB) > > but I suspect that even this wouldn't really solve

Re: limited python virtual machine (WAS: Another scripting language implemented into Python itself?)

2005-01-25 Thread Michael Spencer
Steven Bethard wrote: Michael Spencer wrote: Safe eval recipe posted to cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 This recipe only evaluates constant expressions: "Description: Evaluate constant expressions, including list, dict and tuple using the abstract s

Re: limited python virtual machine (WAS: Another scripting language implemented into Python itself?)

2005-01-25 Thread Michael Spencer
Cameron Laird wrote: In article <[EMAIL PROTECTED]>, Michael Spencer <[EMAIL PROTECTED]> wrote: . . . Right - the crux of the problem is how to identify dangerous objects. My point is that if such as test is po

Re: python without OO

2005-01-25 Thread Michael Spencer
Davor wrote: Thanks, I do not hate OO - I just do not need it for the project size I'm dealing with - and the project will eventually become open-source and have additional developers - so I would prefer that we all stick to "simple procedural" stuff rather than having to deal with a developer that

Re: Classical FP problem in python : Hamming problem

2005-01-27 Thread Michael Spencer
Paul Rubin wrote: Francis Girard <[EMAIL PROTECTED]> writes: Thank you Nick and Steven for the idea of a more generic imerge. If you want to get fancy, the merge should use a priority queue (like in the heapsort algorithm) instead of a linear scan through the incoming iters, to find the next item

Re: remove duplicates from list *preserving order*

2005-02-03 Thread Michael Spencer
Steven Bethard wrote: I'm sorry, I assume this has been discussed somewhere already, but I found only a few hits in Google Groups... If you know where there's a good summary, please feel free to direct me there. I have a list[1] of objects from which I need to remove duplicates. I have to mai

Re: List mapping question

2005-02-03 Thread Michael Spencer
Marc Huffnagle wrote: I have a number of variables that I want to modify (a bunch of strings that I need to convert into ints). Is there an easy way to do that other than saying: > a = int(a) > b = int(b) > c = int(c) It may not matter to you, at the moment, but a = int(a) is not strictly '

Re: how to generate SQL SELECT pivot table string

2005-02-03 Thread Michael Spencer
McBooCzech wrote: Hallo all, I am trying to generate SQL SELECT command which will return pivot table. The number of column in the pivot table depends on the data stored in the database. It means I do not know in advance how many columns the pivot table will have. For example I will test the databa

Re: Popularizing SimpleHTTPServer and CGIHTTPServer

2005-02-04 Thread Michael Spencer
Jorey Bump wrote: > ... Is there a NotSoSimpleHTTPServer? ... Steve Holden wrote: > ... You want ExtremelyBloodyComplicatedHTTPServer :-) Lee Harr wrote: ... I think I would point to twisted for that. Michael :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: returning True, False or None

2005-02-04 Thread Michael Spencer
Steven Bethard wrote: I have lists containing values that are all either True, False or None, e.g.: [True, None, None, False] [None, False, False, None ] [False, True, True, True ] etc. For a given list: * If all values are None, the function should return None. * If at leas

Re: changing local namespace of a function

2005-02-04 Thread Michael Spencer
Bo Peng wrote: Dear list, I have many dictionaries with the same set of keys and I would like to write a function to calculate something based on these values. For example, I have a = {'x':1, 'y':2} b = {'x':3, 'y':3} def fun(dict): dict['z'] = dict['x'] + dict['y'] fun(a) and fun(b) will set

Re: changing local namespace of a function

2005-02-04 Thread Michael Spencer
Bo Peng wrote: Michael Spencer wrote: > There are hundreds of items in the dictionary (that will be needed in the calculation) so passing the whole dictionary is a lot better than passing individual items. ... def fun(d): exec 'z = x + y' in globals(), d seems to be more readable

Re: returning True, False or None

2005-02-04 Thread Michael Spencer
Fahri Basegmez wrote: reduce(lambda x, y: x or y, lst) works but when I tried import operator reduce(operator.or_, lst) this did not work. It pukes Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for |: 'NoneType' and 'bool' Any comments? Fahri Ty

Re: changing local namespace of a function

2005-02-04 Thread Michael Spencer
Nick Coghlan wrote: Michael Spencer wrote: def fun(dict): # set dict as local namespace # locals() = dict? z = x + y As you no doubt have discovered from the docs and this group, that isn't doable with CPython. Not entirely impossible: Py> def f(d): ... exec "loca

Re: returning True, False or None

2005-02-04 Thread Michael Spencer
Fahri Basegmez wrote: "Michael Spencer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Fahri Basegmez wrote: reduce(lambda x, y: x or y, lst) works but when I tried import operator reduce(operator.or_, lst) this did not work. It pukes Traceback (most recent c

Re: changing local namespace of a function

2005-02-05 Thread Michael Spencer
Alex Martelli wrote: Hmmm, you do realize that wrapdict uses a lot of indirection while my equivalent approach, just posted, is very direct, right? To reiterate the latter, and dress it up nicely too, it's class wrapwell(object): def __init__(self, somedict): self.__dict__ = somedict B

Re: empty classes as c structs?

2005-02-05 Thread Michael Spencer
Alex Martelli wrote: Nick Coghlan <[EMAIL PROTECTED]> wrote: ... Michael Spencer also posted ... Wasted indirection, IMHO. A better implementation: class attr_view(object): def __init__(self, data): self.__dict__ = data Alex Indeed! A complete brain-blip Michael -

  1   2   3   4   5   >