Re: How to read/write a field in MariaDB already managed/encrypted by PHP script.

2020-01-25 Thread I

on 2020-01-25 at 12:08 user ^Bart wrote:

Hy guys,

I'm doing a software with a login/register area by Python 3 and PHP 
7.3, i followed this guide 
https://www.9lessons.info/2016/04/php-login-system-with-pdo-connection.html 
and it store the password in encrypted mode but now I need to 
understand how to set the same cypher in Python! :\


^Bart



everyone and his son uses oasswords, truth is, passwords totally suck.


do not ver use shitty passwords, mate

--
https://mail.python.org/mailman/listinfo/python-list


Re: Ruby/Python/REXX as a MUCK scripting language

2006-11-26 Thread i
Tony Belding skrev:

> I'm interested in using an off-the-shelf interpreted language as a
> user-accessible scripting language for a MUCK.  I'm just not sure if I
> can find one that does everything I need.  The MUCK must be able to
> call the interpreter and execute scripts with it, but the interpreter
> must also be able to call functions in the MUCK code.  And then there's
> the security issue that really worries me. . .  I have to be able to
> limit what the interpreter can execute.  I can't have my users running
> scripts that access the console, access the filesystem or sockets
> directly, or call libraries or other binaries outside the MUCK.
>
> Is this practical?  I'm thinking of Ruby or Python for this, if they
> can meet the requirements.
>
> I might even consider REXX. . .  I remember ARexx from my Amiga days,
> and how great it was for string manipulation and application scripting.
>  However. . .  My immediate target platform, Mac OS X, comes with Ruby
> and Python but not REXX, so that's a disadvantage.
>
> My final option would be to create my own language interpeter where I
> have control over everything that happens.  That is what MUCKs have
> always done in the past.  But the result was always quirky, limited
> languages like MUF (Multi-User Forth) which really turn off a lot of
> coders.  Furthermore, I've never created a language before, and it
> would be a lot of extra work for me.
>
> --
> Tony Belding, Hamilton Texas

Regina REXX har a "restricted mode", but it doesn't allow external
calls so this is probably not a solution for You.  Nevertheless, here
is an excerpt from the manual about that mode:

"2.6.3Regina Restricted Mode
Many language interpreters provide a mechanism where code executed
within that interpreter is
limited to affecting the environment of the interpreter and cannot
change the external environment
in which the interpreter runs.
Restricted mode is used in situations where you need to guarantee that
the author of a Rexx
program is unable to affect the user's environment.
Situations where a restricted mode is applicable include, using Regina
as a database procedural
language, or as a language plug-in for a Web browser.
Features of Regina that are disabled in restricted mode are:
·  LINEOUT, CHAROUT, POPEN, RXFUNCADD BIFs
·  "OPEN WRITE", "OPEN BOTH" subcommands of STREAM BIF
·  The "built-in" environments eg. SYSTEM, CMD or PATH of ADDRESS
command
·  Setting the value of a variable in the external environment with
VALUE BIF.
·  Calling external functions
To run Regina in restricted mode, you can start the Regina interpreter
from the command line with
the '-r' switch, or when using the Rexx SAA API, or-ing RXRESTRICTED to
the CallType
parameter of RexxStart() function."

Thomas Berg

-- 
http://mail.python.org/mailman/listinfo/python-list

A computer programmer, web developer and network admin resume

2013-05-21 Thread i...@databaseprograms.biz
A computer programmer, web developer and network administrator resume.

For a resume in HTML or .Doc format click on:
www.DatabasePrograms.Biz<http://www.databaseprograms.biz/>

If you would like this in text format instead, please let me know.


Daniel Rapaport

1-949-307-2485
i...@databaseprograms.biz<mailto:i...@databaseprograms.biz>







To unsubscribe click on: 
i...@databaseprograms.biz?Subject=unsubscribe<mailto:i...@databaseprograms.biz?Subject=unsubscribe>

-- 
http://mail.python.org/mailman/listinfo/python-list


see the link

2011-04-08 Thread ramalingam i
webpage : http://123maza.com/65/hand741/
-- 
http://mail.python.org/mailman/listinfo/python-list


Main threads waits indefinitely on futures if single future calls condition.wait()

2019-10-31 Thread i...@dantalion.nl
Hello,

Recently I have been trying to use a reantrant read write lock in my
project but discovered several problems when writing test cases.

All the relevant material can be found on the following locations
https://stackoverflow.com/questions/58410610/calling-condition-wait-inside-thread-causes-retrieval-of-any-future-to-block-o
https://bugs.launchpad.net/futurist/+bug/1848457
https://github.com/Dantali0n/bug1848457

But let me describe it here as well.
I am using the futurist library maintained by the OpenStack foundation.
This library provides concurrency constructs similar to those of Python
itself. Among the functionality is a wait_for_any method which waits on
a list of futures and continuous once one of them is done().

However, when I submit two tasks to a threadpool which both attempt to
get a reantrant read write lock this wait_for_any method behaves
unexpectedly. Since both tasks attempt to get the lock concurrently one
will succeed and the other will not. The behavior of this lock is to
call condition.wait() if it does not succeed.

The unexpected behavior of the wait_for_any method is that in this
scenario it will block indefinitely when called even though one of the
futures is done() and finished successfully.

In https://github.com/Dantali0n/bug1848457 I have created a spin_for_any
using the same lock but with 'native' Python concurrency and here
calling future.done() does not block.

I was hoping someone had any clue as to what could cause this and how it
can be resolved. As mentioned before the question is also over on
stackoverflow, I have been struggling with this for a month now.

I hope someone has time to provide some help on this matter.

Kind regards,
Corne Lukken (Dantali0n)
-- 
https://mail.python.org/mailman/listinfo/python-list


Llearn a Little About Artificial Neural Networks and TKinter

2005-04-29 Thread I. Myself
The VizANN package is a free download from annevolve.sf.net.  It 
contains a python program
that graphically demonstrates a recurrent binary neural network.  There 
is also an explanatory text file.

Mitchell Timin
--
"In theory, there is no difference between theory and practice.  In
practice, there is."
http://annevolve.sourceforge.net is for those seeking something to do with 
their wetware.
Humans may know that my email address is zenguy at shaw dot ca.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Figuring out what dependencies are needed

2013-12-11 Thread sal i
On Thursday, December 12, 2013 1:48:42 PM UTC+8, alex23 wrote:
> On 11/12/2013 10:44 PM, s...@nearlocal.com wrote:
> 
> > I'm a Python beginner.  I want to use it for stats work, so I downloaded 
> > Anaconda which has several of the popular libraries already packaged for 
> > Mac OS X.
> 
> >
> 
> > Now I'd like to use the backtesting package from zipline (zipline.io), but 
> > while running the test script in iPython, I receive the following error:
> 
> >
> 
> > AssertionErrorTraceback (most recent call last)
> 
> >  in ()
> 
> > > 1 data = load_from_yahoo()
> 
> >2 dma = DualMovingAverage()
> 
> >3 results = dma.run(data)
> 
> >
> 
> > 1)  I assume that I'm missing some packages that aren't included in 
> > Anaconda, but how do I know which ones to upload?
> 
> 
> 
> You're not missing a package, you're missing parameters. This is the 
> 
> signature for load_from_yahoo:
> 
> 
> 
>  def load_from_yahoo(indexes=None,
> 
>  stocks=None,
> 
>  start=None,
> 
>  end=None,
> 
>  adjusted=True):
> 
> 
> 
> The first thing it does is call a helper function 
> 
> `_load_raw_yahoo_data`, which has this assertion:
> 
> 
> 
>  assert indexes is not None or stocks is not None, """
> 
> 
> 
> As you're passing no parameters into `load_from_yahoo`, both `indexes` 
> 
> and `stocks` default to None, so the assertion fails. Take a look at the 
> 
> examples in the zipline library to see what it is expecting.
> 
> > 2)  Often I'll just unzip a library file and put the main folder in the 
> > iPython folder, but I notice there's usually a setup.py file in the main 
> > library folder.  I've been ignoring this.  Should I be using it?
> 
> >
> 
> > Thanks
> 
> >

Thanks everyone.

This is the entire testing file along with the error at the bottom.  It looks 
like a stock is specified as data['AAPL']:

%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [14]:

from zipline.algorithm import TradingAlgorithm
from zipline.transforms import MovingAverage
from zipline.utils.factory import load_from_yahoo
In [15]:

class DualMovingAverage(TradingAlgorithm):
"""Dual Moving Average algorithm.
"""
def initialize(self, short_window=200, long_window=400):
# Add 2 mavg transforms, one with a long window, one
# with a short window.
self.add_transform(MovingAverage, 'short_mavg', ['price'],
   market_aware=True,
   window_length=short_window)
 
self.add_transform(MovingAverage, 'long_mavg', ['price'],
   market_aware=True,
   window_length=long_window)
 
# To keep track of whether we invested in the stock or not
self.invested = False
 
self.short_mavg = []
self.long_mavg = []
 
 
def handle_data(self, data):
if (data['AAPL'].short_mavg['price'] > data['AAPL'].long_mavg['price']) 
and not self.invested:
self.order('AAPL', 100)
self.invested = True
elif (data['AAPL'].short_mavg['price'] < 
data['AAPL'].long_mavg['price']) and self.invested:
self.order('AAPL', -100)
self.invested = False
 
# Save mavgs for later analysis.
self.short_mavg.append(data['AAPL'].short_mavg['price'])
self.long_mavg.append(data['AAPL'].long_mavg['price'])
 
In [16]:

data = load_from_yahoo()
dma = DualMovingAverage()
results = dma.run(data)
---
AssertionErrorTraceback (most recent call last)
 in ()
> 1 data = load_from_yahoo()
  2 dma = DualMovingAverage()
  3 results = dma.run(data)

/Users/my_mac/zipline/data/loader.pyc in load_from_yahoo(indexes, stocks, 
start, end, adjusted)
302 
303 """
--> 304 data = _load_raw_yahoo_data(indexes, stocks, start, end)
305 if adjusted:
306 close_key = 'Adj Close'

/Users/my_mac/zipline/data/loader.pyc in _load_raw_yahoo_data(indexes, stocks, 
start, end)
245 
246 assert indexes is not None or stocks is not None, """
--> 247 must specify stocks or indexes"""
248 
249 if start is None:

AssertionError: 
must specify stocks or indexes
-- 
https://mail.python.org/mailman/listinfo/python-list


TALK.ORIGINS CENSORS THE TRUTH

2014-03-12 Thread I THRINAXODON

EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# 



https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# 





http://thrinaxodon.wordpress.com/

===

THRINAXODON ONLY HAD THIS TO SAY:

"I..I...I...Can't believe it. This completely disproved Darwinian
orthodoxy."

===

THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING
WITH FEAR.

===
THESE ASSHOLES ARE GOING TO DIE:
THOMAS AQUINAS;
ALDOUS HUXLEY;
BOB CASANVOVA;
SkyEyes;
DAVID IAIN GRIEG;
MARK ISAAK;
JOHN HARSHAM;
RICHARD NORMAN;
DR. DOOLITTLE;
CHARLES DARWIN;
MARK HORTON;
ERIK SIMPSON;
HYPATIAB7;
PAUL J. GANS;
JILLERY;
WIKI TRIK;
THRINAXODON;
PETER NYIKOS;
RON OKIMOTO;
JOHN S. WILKINS
===

THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A
HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT
THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD
TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY
FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep
people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS
SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That
is a myth, for people to believe in science." THRINAXODON PLANS TO
BRING DOOM TO SCIENCE, ITSELF.



THRINAXODON IS NOW ON REDDIT

--
---Thrinaxodon

--
https://mail.python.org/mailman/listinfo/python-list


Question about XMLRPC

2013-08-29 Thread i . sheeha
Hello, 
I should write a python script(s) that listens to an existing XMLRPC service on 
my company's dev server.My utility should take some data from that XMLRPC, send 
it to an online xml service provider(it's something about hotel accomodation, 
where they have xml patterns for different requests), then they return their 
response to me, also in xml data interchange format.then i should parse that 
and return to the existing XML-RPC, or write the parsed data to the Posgresql 
database.The thing is, i know something about XML parsing, i know also 
something about XMLRPC, but i'm not permitted to edit the existing XMLRPC 
service.Can anyone just tell me what is the shortest and the best solution for 
this problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread I V
On Fri, 20 Oct 2006 09:04:07 +1000, Steven D'Aprano wrote:
> I agree -- the reversed() function appears to be an obvious case of purity
> overriding practicality :(
> 
>>>> str(reversed("some string"))
> ''
>>>> repr(reversed("some string"))
> ''

This doesn't seem particularly "pure" to me, either. I would
have thought str(some_iter) should build a string out of the iterator, as
list(some_iter) or dict(some_iter) do. I guess this might have to wait for
Python 3, but str ought to be a proper string constructor, not a "produce
a printable representation of" function, particularly when we have repr to
do the latter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Programmer Question

2006-06-26 Thread I V
On Mon, 26 Jun 2006 10:47:58 -0700, [EMAIL PROTECTED] wrote:
> whats the difference between raw input and input?

'input' is used to ask the user to input a python expression, which is
then run, and 'input' returns the result of executing that expression. For
example:


(define a function which prints something out)

>>> def func():
... print "You're calling a function"
... return "Function result"
...

(now, call input)

>>> res = input('Type python here: ')

(python outputs the prompt )

Type python here:

(and, if you type the python code to call a function after the prompt)

Type python here: func()

(then python calls the function, which prints out)

You're calling a function

(meanwhile, the result of calling the function gets assigned to 'res')

>>> print res
Function result

'raw_input' just returns whatever text the user typed in. That's what you
want to use here. 'raw_input' returns a string, which you'll need to
convert to a number with the 'int' function, like so:

text = raw_input('Type in a number: ')
number = int(text)




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replace Whole Object Through Object Method

2006-06-27 Thread I V
On Mon, 26 Jun 2006 19:40:52 -0700, digitalorganics wrote:
> A misuse of inheritance eh? Inheritance, like other language features,
> is merely a tool. I happen to be using this tool to have my virtual
> persons change roles at different points in their lifetime, as many
> real people tend to do. Thus, at these points, B is indeed an A. What a
> person is, whether in real life or in my program, is not static and
> comes into definition uniquely for each moment (micro-moment, etc.) of
> existence. Now, please, I have no intention of carrying the
> conversation in such a silly direction, I wasn't inviting a discussion
> on philosophy or some such. I seek to work the tools to my needs, not
> the other way around.

But thinking about the problem in the vocabulary provided by the
programming language can be helpful in coming up with a solution. If
inheritance tells you what an object _is_, and membership tells you what a
role _has_, and a role is something that a person has, that suggests
that an implementation where roles are members of a person might be
simpler than trying to use inheritance. Like, for instance:

class Role(object):
def __init__(self, person):
self.person = person


class Worker(Role):
def do_work(self):
print self.name, "is working"


class Employer(Role):

def __init__(self, person):
Role.__init__(self, person)
self.employees = []


def add_employee(self, worker):
self.employees.append(worker)


def boss_people_around(self):
for employee in employees:
print self.name, "is telling", employee.name, "what to 
do"


class Person(object):

def __init__(self, name):
self.roles = []
self.name = name


def add_role(self, role_class):
self.roles.append(role_class(self))


def forward_to_role(self, attr):
for role in self.roles:
try:
return getattr(role, attr)
except AttributeError:
pass
raise AttributeError(attr)


def __getattr__(self, attr):
self.forward_to_role(attr)


bill = Person('Bill')
bill.add_role(Worker)

bob = Person('Bob')
bob.add_role(Employer)

bill.work()
bob.boss_people_around()

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-12 Thread I V
On Mon, 11 Dec 2006 23:24:07 -0500, Ken Tilton wrote:
> Also, Python does not support a functional style of programming so the 
> line is the only meaningful textual entity. In this sense the 
> primitiveness of Python makes editing easier.

Why do you say that? Wouldn't a block in python be a "meaningful textual
entity" in the same way a lisp form would be?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-12 Thread I V
On Sun, 10 Dec 2006 03:18:07 -0500, Bill Atkins wrote:
> We're not counting lines here, you goon.  We're talking about how
> expressive constructs are and how closely they match your concept of
> what you want to do.  The conditional example is lower-level; you're
> talking to the interpreter instead of saying what you want to achieve.
> You're having to repeat things because that's what the language asks
> of you, instead of describing in a higher-level way what you're
> actually doing.

To be a little provocative, I wonder if the idea that you're "talking to
the interpreter" doesn't apply more to lisp than to python; you can have
any syntax you like, as long as it looks like an AST. 

One of the things I've always found off-putting about lisp as that all the
syntax looks the same. In Algol-derived languages, each syntactic
construct has a fairly distinctive appearance, so when, for instance, I
encounter a for loop, I can quickly recognize that that's what it is, and
bracket out the "scaffolding" and pick out the details that interest me.
With lisp, I can't do that, I have to read through the sexp, decide on
what syntax it is, and then remind myself where to look for the relevant
specific details.

Now, this might well be just due to my comparative lack of familiarity
with lisp; I'd be interested to hear if you lisp people find different
lisp constructs as visually distinctive as constructs in python (or other
similar languages). But I think what people are getting at when they
complain about "all the brackets" in lisp may actually be this issue of
a visual distinction between different constructs (this is also a reason
why having a limited number of syntactic constructs can be helpful - there
are a probably a  limited number of stereotypical layouts a programmer can
keep in their mind at once).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making dir's

2006-01-22 Thread I V
Klaus Alexander Seistrup wrote:
> Or os.makedirs():

Although that may or may not do what the OP wants. I was assuming she
was trying to produce a directory structure like:

/dir/C/
/dir/ASM/
/dir/Python/

os.makedirs() produces a directory hierarchy, like:

/dir/C/ASM/Python/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple question string.replace

2006-01-30 Thread I V
Haibao Tang wrote:
> Is it possible to substitue all '1.1' to some value else without using
> re.

You could try:

import sys

values = sys.stdin.readline().split()
while values:
results = []
for value in values:
if value != '1.1':
results.append(value)
else:
results.append('something else')

print '\t'.join(results)
values = sys.stdin.readline().split()

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO conventions

2006-02-03 Thread I V
Nicola Musatti wrote:
> I don't think this is all there is to it. Even though a class such as
> Image might not have a sensible default, initial state it still might
> not be reasonable to burden it with the ability to collect the
> information needed to reach such an initial state. To put it it another
> way: a car is a car, it isn't a car factory.

What's the "burden", though? Surely the only burden is that the class
needs to take the relevant parameters to its __init__ method, which is
no more of a burden than providing some other initialization method
that takes the relevant parameters.

> Factory functions (or classes) are there to solve this problem and
> still allow a clean separation of concerns. Although instances of Klass
> are created uninitialized, they only live in this state within their
> factory and only reach trhe outside world only when they are in a
> usable state.

This may be my limited imagination, but I can't think of a situation
when you would prefer something like:

def factory(info):
k = Klass()
data = get_initial_data(info)
k.set_data(data)
return k

to:

def factory(info):
data = get_initial_data(info)
return Klass(data)

What would be the value of doing the initialization in a separate
method, rather than the constructor?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to *Search* with google from inside my programme and get the search result?

2006-02-14 Thread I V
Frank Potter wrote:
> Does google supply some webservice to programmers? I did see

Googling for "google api" gets you to:

http://www.google.com/apis/

It appears to be a SOAP API, which you can access with python, but I
think you'll need a third-party library. Googling for "python soap"
gets you:

http://www-128.ibm.com/developerworks/library/ws-pyth5/

which might be a place to start.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ls files --> list packer

2006-02-23 Thread I V

kpp9c wrote:
> Namely i have organized a bunch of folders that have soundfiles in them
> and would like Python to slurp up all the .aif/.aiff (or .wav whatever)
> files in a given set of directories. My friend hacked up this is perl:
>
> $files = `ls /snd/Public/*.aiff`;

You could use posix.popen to duplicate the perl hack:

files = posix.popen('ls /snd/Public/*.aiff').read().strip()

> @snd_filelist = split('\n',$files);

snd_filelist = files.split('\n')

> I would like something similar, that works with python that is more
> elegant and maybe even more robust.

Lucklily, python lets you avoid this kind of horrible hack. Try
os.listdir:

snd_filelist = [f for f in os.listdir('/snd/Public/') if
f.endswith('.aiff')]

I think it's more elegant, and it's certainly more robust.

> but i am failing miserably and my perl friends mock me.

Now you get to mock your perl friends!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 354: Enumerations in Python

2006-02-27 Thread I V
Paul Rubin wrote:
> Hmm, I also see the PEP doesn't specify what's supposed to happen with
>
>   Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
>   Solar_system = enum('sun', 'mercury', 'venus', 'earth',)  # etc.
>   print Weekdays.sun == Solar_system.sun
>
> so that's another shortcoming with the PEP.

I think it does, doesn't it? From the PEP:

"Values within an enumeration cannot be meaningfully compared *except
with values from the same enumeration*.  The comparison operation
functions return ``NotImplemented`` [#CMP-NOTIMPLEMENTED]_ when a
value from an enumeration is compared against any value not from the
same enumeration or of a different type." (my emphasis)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Like Christ PBBUH Prayed

2005-05-17 Thread I Know
oh, just 
shut
the
fuck
up
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Goto

2007-06-17 Thread Tina I
Daniel Nogradi wrote:
>> How does one effect a goto in python? I only want to use it for debug.
>> I dasn't slap an "if" clause around the portion to dummy out, the
>> indentation police will nab me.
> 
> 
> http://entrian.com/goto/
LOL!! * major flashback to horrible BASIC programs from the eighties *

Back then I took a course in structured BASIC programming (now there is 
a contradiction in terms) and the instructor warned about goto time and 
time again. But his biggest mistake was to tell us that if we had to use 
goto at least we should explain it in a comment. So we would turn in 
programs with sections like:

100 IF S$="YES" THEN GOTO 150
110 REM Go to line 150 if S$ is Yes


Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python extra

2007-07-11 Thread Tina I
[EMAIL PROTECTED] wrote:
> On Jul 8, 12:59?pm, Neal Becker <[EMAIL PROTECTED]> wrote:
>> Just a little python humor:
>>
>> http://www.amazon.com/Vitamin-Shoppe-Python-Extra-tablets/dp/B00012NJ...
> 
> Aren't there any female Python programmers?
> 
No, of course not.
Oh, and guys: If you take those pills please observe the warning; 
"Safety information: Do not use if you are pregnant or nursing!"
:P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner: Formatting text output (PyQt4)

2007-04-18 Thread Tina I
Glen wrote:


>> Hello again,  I don't blame anyone for not answering my last post,
> since
>> I obviously hadn't spent much time researching, but I've come a little
>> ways and have another question.
>>
>> How can I better format text output to a QTextEdit object?  I'm
>> inserting 5 columns into each row.  When I write the info to a file, it
>> looks like the following:
>>
>> 42: 115 26: 114 35: 112 19: 108 16: 107 45: 107 40:
>> 106  5: 105 41: 104  2: 103
>>  9: 102 48: 102 15: 101 22: 101 27: 101
>> 39: 101 43: 101 10: 100  6:  99 34:  99 32:  98 49:
>> 98 20:  97 30:  97  8:  96 17:  96 38:  96 12:  95
>> 14:  95 37:  95
>>  4:  94 13:  94 44:  94 36:  93  3:  92
>> 24:  92 28:  92 31:  91 29:  89  7:  88
>>  1:  87 18:  85 46:  85 33:  84 11:  83
>> 23:  83 47:  82 25:  80 21:  79 50:  56 52:  39 51:
>> 38 53:  36 54:  25 55:  18
>>
>> When I write the contents of the file to my TextEdit object it comes out
>> uneven, something like this:
>> 42: 11526: 11435: 11219: 10816: 107 45: 10740: 106
>> 5: 10541: 104 2: 103 9: 10248: 10215: 10122: 101 27:
>> 101 39: 10143: 10110: 1006:  9934:  99 32:  9849: 98
>>20:  9730:  978:  96 17:  9638:  9612:  9514: 95
>>   37:  95 4:  9413:  9444:  9436:  933:  92 24:  92 28:
>> 9231:  9129:  897:  88
>>  1:  8718:  8546:  8533:  8411:  83
>> 23:  8347:  8225:  8021:  7950:  56 52:  3951:  38
>> 53:  3654:  2555:  18
>>
>> What seems to be happening is that the font that pyqt is using is not
>> fixed width, so I did this:
>>  qTxtFormat = QTextCharFormat()
>>  qTxtFormat.setFontFixedPitch(True)
>>  ui.textEdit.setCurrentCharFormat(qTxtFormat)
>>
>> Also, I tried using the pyqt formatting such as the following:
>>
>>  qStr = QtCore.QString( QtCore.QString( str(tL2[i][0])
>>  ).rightJustified(2) + ':' + QtCore.QString( str(tL2[i][1])
>>  ).rightJustified(4) )
>> This still gives me uneven columns.
>>
>> Any suggestions?
>>
>> Thanks,
>>
>> Glen
> 
Do you need to use QTextEdit for the output? Sounds like maybe you 
should look at for example the QTableWidget or maybe the QTreeWidget?

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Catching a specific IO error

2007-04-24 Thread Tina I
Hi group :)

I have this standard line:

export = open(self.exportFileName , 'w')

'exportFileName' is a full path given by the user. If the user gives an 
illegal path or filename the following exception is raised:
"IOError: [Errno 2] No such file or directory: /some/path/file.txt"

So at the moment I do this:

try:
export = open(self.exportFileName , 'w')
export.write("Something")
export.close()
except IOError:
# calling an error handling method.

Now, this works but of course it catches every IOError, and I can not 
figure out how to restrict it to only catch the "[Errno 2]"?

Thanks
Tina

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Catching a specific IO error

2007-04-25 Thread Tina I
Gabriel Genellina wrote:
> You can get the 2 as the errno exception attribute. BTW, 2 == errno.ENOENT
> 
>  try:
>  export = open(self.exportFileName , 'w')
>  except IOError, e:
> if e.errno==errno.ENOENT:
> # handle the "No such file or directory" error
>  # calling an error handling method.
> 
> See http://docs.python.org/lib/module-exceptions.html
> 
> --Gabriel Genellina

Perfect! Just what I was looking for. Thank you! :)

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lowercase class names, eg., qtgui ? (PyQt4)

2007-04-26 Thread Tina I
Glen wrote:
> Hello,
> 
> In the file generated by pyuic4 from Designer's .ui file I noticed the use
> of lower case class names (I'm assuming these are the names of classes,
> not modules).  For example:
> 
> It imports thusly:
> 
> from PyQt4 import QtGui
> 
> then uses things like:
> self.gridlayout = qtgui.qgridlayout(dldialog)
> 
> What exactly is going on here?  Are these instances that are defined
> somewhere else (their not in the local scope.)? Can I do the same in my
> code when I import something?
> 
> Thanks,
> 
> Glen
> 
> Glen
> 
Hi,

Are you sure? That's strange. I have never seen that. Here is a snippet 
of one of my typical .py files generated by 'pyuic4':

self.gridlayout = QtGui.QGridLayout(self.centralwidget)
self.gridlayout.setMargin(9)
self.gridlayout.setSpacing(6)
self.gridlayout.setObjectName("gridlayout")

self.hboxlayout = QtGui.QHBoxLayout()
self.hboxlayout.setMargin(0)
self.hboxlayout.setSpacing(6)
self.hboxlayout.setObjectName("hboxlayout")

self.hboxlayout1 = QtGui.QHBoxLayout()
self.hboxlayout1.setMargin(0)
self.hboxlayout1.setSpacing(6)
self.hboxlayout1.setObjectName("hboxlayout1")

Upper case all the way...

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how update a qListView in backgroud

2007-05-02 Thread Tina I
Reinaldo Carvalho wrote:
> Hi,
> 
> I programming with qt module and i have a qWidgetTab with a qListView
> inside, and i need update the qListView every 5 seconds, how do this
> on transparent mode to user. I do a function to update, but i dont
> know call then.
> 
> I will start this update when user select this tab, and stop whe user
> leave this tab. I need a thread ot something else?
> 
Assuming PyQt4 here:
Check out QTimer. Have it start when the user selects the tab and have 
it timeout every five seconds calling the update function.

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Init style output with python?

2007-05-05 Thread Tina I
Maxim Veksler wrote:

> Is there are frame work or something in python that would allow me to
> do this (quickly) ?
> If not, ideas how I should I be getting this boring task of:
> 1. get screen width

You can look into the 'curses' module and do something like:

screen = curses.initscreen()
maxheight, maxwith = screen.getmaxyx()

In my experience curses can be a bit tricky to work with but the online 
tutorials have some nice examples that help you avoid some of the 
pitfalls (like messing up your terminal)

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Distributing programs depending on third party modules.

2007-05-15 Thread Tina I
Hi list,

Is there a preferred way to distribute programs that depends on third 
party modules like PyQt, Beautifulsoup etc? I have used setuptools and 
just having the setup script check for the existence of the required 
modules. If they're not found I have it exit with a message that it need 
this or that installed.

But this is not very convenient for the end user and I have got a few 
complaints about it. Am I missing something in setuptools or is there a 
better way to do it (except for bundling the modules in the package 
which seem like a rather nasty workaround)?

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distributing programs depending on third party modules.

2007-05-15 Thread Tina I
Kevin Walzer wrote:
> 
> What platform are you doing this on? On the Linux platform, "dependency 
> hell" of this sort is pretty much unavoidable, because there are so many 
> different packaging systems (apt, rpm, and so on): it's standard to let 
> the package manager handle these dependencies. And yes, it is 
> frustrating for end users.
I mainly write apps for Linux although some are in theory cross platform 
(but I don't have Windows to test on so I don't really care about that 
part). Of course catering to every concievable package management system 
is impossible so I'm looking for something to make it easy for people to 
use the app as it is.
> 
> There are other methods for distributing "frozen binaries," including 
> the freeze module that ships with Python itself, cx_freeze, and 
> PyInstaller: these three may work on Linux/Unix as well as Windows (they 
> are not supported on the Mac). But the methods above are generally the 
> ones most widely used.
> 
A binary would be ideal. I'll look into the freeze modules and 
Pyinstaller. Even if they don't handle huge things like Qt it would be a 
step in the right direction if it handles smaller third part modules.
And maybe the smartest thing to do would be to dump PyQt and just go for 
tkinter, however ugly it is :/

Anyways, thanks for the help people
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distributing programs depending on third party modules.

2007-05-16 Thread Tina I
David Boddie wrote:
> On May 16, 7:44 am, Tina I <[EMAIL PROTECTED]> wrote:
> 
>> A binary would be ideal. I'll look into the freeze modules and
>> Pyinstaller. Even if they don't handle huge things like Qt it would be a
>> step in the right direction if it handles smaller third part modules.
>> And maybe the smartest thing to do would be to dump PyQt and just
>> go for tkinter, however ugly it is :/
> 
> It's may be worth reading this message before making such a drastic
> decision:
> 
> http://www.riverbankcomputing.com/pipermail/pyqt/2007-May/016092.html
> 
> David ;-)
> 
Oh... now I feel stupid... I'm on the PyQt list but somehow missed that 
topic.
Thanks!

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distributing programs depending on third party modules.

2007-05-16 Thread Tina I
Kevin Walzer wrote:
> Tina I wrote:
>> Kevin Walzer wrote:
> 
> 
>> And maybe the smartest thing to do would be to dump PyQt and just go 
>> for tkinter, however ugly it is :/
> 
> Tkinter doesn't have to be ugly.
> 
> I sell a proprietary Tkinter app commercially on OS X:
> 
> http://www.codebykevin.com/phynchronicity-running.png
> 

Thanks, looks very nice :)
I'll play around with Tkinter a little and maybe try it out for my next 
project just for fun.

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CP4E revival

2007-05-24 Thread I V
On Thu, 24 May 2007 20:03:29 +1000, Richard Jones wrote:
> Hoop-jumping implemented to prevent just this kind of direct linking (and
> thus not saving of the PDF to local disk to view, and thus increasing the
> load on the server).

I'm not sure I see the connection - if you're serving something as
application/pdf, then people are going to download it or view it directly
as they see fit (or as their browser is configured), whether or not they
got their by clicking a link or pressing two buttons (indeed, using the
buttons makes it _harder_ to save the PDF to disk, if that's what you want
to enforce, because users can't right-click/save-as; if their browser is
set up to open PDFs directly, they can't change that behavior without
reconfiguring their browser).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unsubscribing from the mailing list

2007-05-28 Thread Tina I
[EMAIL PROTECTED] wrote:
> Hi All,
> 
> I do not know if this is the correct group to ask this question. But
> since mailman is python-based I thought i would ask here.
> 
> I had subscribed to a mailing list called [EMAIL PROTECTED]
> adventitiously. I then wanted to reverse my decision and so tried to
> unsubscribe from the mailing list. The web interface told that I had
> to enter my username and then click unsubscribe. I did so. I was
> responded with the message that "A confirmation mail has been sent".
> However I did not get any mail of that sort. Due to this I am not able
> to unsubscribe and I get loads of emails from that mailing list every
> day.
> 
> Can somebody help me get out of this mess??
> 
> Thanks,
> Sundar
> 
Umm... why not ask on [EMAIL PROTECTED] ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: split on NO-BREAK SPACE

2007-07-22 Thread I V
On Sun, 22 Jul 2007 21:13:02 +0200, Peter Kleiweg wrote:
> Here is another "space":
> 
>   >>> u'\uFEFF'.isspace()
>   False
> 
> isspace() is inconsistent

Well, U+00A0 is in the category "Separator, Space" while U+FEFF is in the
category "Other, Format", so it doesn't seem unreasonable that one is
treated as a space and the other isn't.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Submit form, open result in a browser

2007-07-27 Thread Tina I
theju wrote:
>> Is there a way to submit a form and then open the resulting page in the
>> default browser? (Writing the form submission code is not a problem by
>> the way)
> 
> There is a library called "Client Form" that does this for you.
> wwwsearch.sourceforge.net/ClientForm/
> 
> After the form is submitted through ClientForm open the resulting
> response using the webbrowser module.
> 
> Cheers
> Thejaswi Puthraya
> 

ClientForm is absolutely perfect! Less than 10 lines of extra code and 
the job is done :)

Thanks!
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Submit form, open result in a browser

2007-07-27 Thread Tina I
Hi,

Is there a way to submit a form and then open the resulting page in the 
default browser? (Writing the form submission code is not a problem by 
the way)
I guess what I'm asking is how I can get the resulting URL and feed it 
to the webbrowser module.
I need to do it this way because the site owners will not let me parse 
the page and show the result inside my application... loss of 
advertising revenue I guess. And since it's just a small added feature 
to the application, opening it in a browser is fine. I just need to get 
an idea on how to do it...

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wikicodia - The code snippets wiki

2007-07-28 Thread Tina I
Wikicodia Admin wrote:
> Dears,
> 
> Wikicodia is a wiki based project for sharing code snippets. We're
> collecting large number of code snippets for all code-based
> programming languages, scripts, shells and consoles. We wish you could
> help us. We're still BETA. Your suggestions, ideas and criticisms are
> very welcomed. We're waiting for you contributions. You can easily
> share and search our snippet using our Google Desktop Gadget. Share
> your Python snippets to help the world :)
> 
> http://www.wikicodia.com
> 
> Thanks
> Wikicodia Admin
> 
Just in case you are not aware of it; there already exists a fairly 
identical service called "The Rosetta Code" at http://www.rosettacode.org/

Maybe you could join forces instead? ;-)

Tina
PS: I'm not affiliated with Rosetta in any way...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about a web server

2007-08-20 Thread I V
On Mon, 20 Aug 2007 00:02:47 -0700, Frank Millman wrote:
> When responding to the POST data received, it sends a 301 response, no
> headers, and then the html page.
[...]
> According to the notes, "You don't have to know much about the HTTP
> protocol at all. Except some basic that when the client request
> something it is a "GET", and when the client sends something it is in
> our case a POST. Some basic responce codes like 200 is OK for GET, and
> 404 is file not found, 301 is OK for a Post."
[...]
> I googled for 'http response code 301', and found that it is actually
> a redirection code. It seems that the notes are misleading.
[...]
> So I guess my questions are -
>   1. what is the correct response for a POST?
>  I think the answer is 200.
>  However, I assume the author is trying to demonstrate a
> particular technique.
>  Can anyone explain what that may be.

The code at that site looks wrong to me; I suspect the original author
was confused about status codes. If you return a 301 redirect code, you
should include a Location: header specifying the URI to redirect to, which
that code doesn't do. Also, if you return a redirect code, you probably
shouldn't include any page content (except perhaps a link to the
redirected page). Note also that 301 is a permanent redirect, that is, it
should be used when the URI has changed permanently (and might cause your
browser to, e.g., update its bookmarks). You're probably not going to use
it in normal operation.

I'm not sure what the author was trying to do, but there is one quite
common case where redirects are used with POST request. When the POST
request does something that you are probably not going to want to repeat,
but you want the resulting page to contain information that the user might
want to refresh, it's common to have the POST return a 302 status (a
temporary redirect). 

One example where this is useful is posting comments to a forum or blog.
Usually, when the comment is posted, you want to return to the list of all
the comments. But the user might refresh that list of comments, and you
don't want their comment to be posted again when they refresh. So you
would have the POST for the comment respond, not with a list of comments,
but with a redirect _to_ the list of comments.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-21 Thread I V
On Tue, 21 Aug 2007 21:23:25 -0300, Ricardo Aráoz wrote:
>   Do you know if for in-house development a GPL license applies? (Qt4
> and/or Eric4).

(I'm not sure if I've understood your question right)

If you distribute an app that _uses_ PyQT, you have to comply with the GPL
(or buy a license from Trolltech), but note that this doesn't really have
anything to do with Eric4. Running Eric4 doesn't require a license (either
the GPL or Trolltech), and code you write using Eric4 doesn't have to be
licensed according to the GPL either.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PyQt4: Clickable links in QLabel?

2007-03-07 Thread Tina I
David Boddie wrote:
> On Thursday 01 March 2007 09:00, Tina I wrote:
> 
>> A short and sweet question: Is it possible to put a clickable link in a
>> QLabel that will open in the systems default browser?
> 
> Yes.
> 
>> I tried to put in some HTML but it did (of course?) simply display the
>> code instead of a link. I also tried to set openExternalLinks 'true' but
>> then pyuic4 bombed.
> 
> Well, that shouldn't happen. :-(
> 
> Can you send a bug report to the PyQt mailing list (assuming you're
> subscribed to it) with the error message or backtrace that you get
> when this happens?
> 
>> I see that QLabel does not have a html text format but I'm still hoping
>> it's possible. I really need a link on my main window form.
> 
> If you enclose the HTML with  and  tags, the HTML should be
> displayed properly. Any other matching tags should also work, so you
> could use  and  if you want.
> 
> Setting the label's openExternalLinks property to True should then
> enable what you want. You can try this out by previewing the form in
> Qt Designer.
> 
> David
Thanks David,

This is embarrassing... but my PyQt4 was too old *blush*
I can't believe I didn't think of double checking what version I had 
installed. A swift upgrade and it works like a charm :)

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting user id (from an arbitrary sys user)

2007-03-14 Thread Tina I
Gerardo Herzig wrote:
> hi all. What i need to know is if there is some function like 
> os.getuid(), but taking an argument (the username, off course), so i can 
> do getuid('myuser')
> 
> Thanks you dudes!
> 
> Gerardo
How about simply:

import commands
userid = commands.getoutput("id -u username")

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: difference between urllib2.urlopen and firefox view 'page source'?

2007-03-19 Thread Tina I
cjl wrote:
> Hi.
> 
> I am trying to screen scrape some stock data from yahoo, so I am
> trying to use urllib2 to retrieve the html and beautiful soup for the
> parsing.
> 
> Maybe (most likely) I am doing something wrong, but when I use
> urllib2.urlopen to fetch a page, and when I view 'page source' of the
> exact same URL in firefox, I am seeing slight differences in the raw
> html.
> 
> Do I need to set a browser agent so yahoo thinks urllib2 is firefox?
> Is yahoo detecting that urllib2 doesn't process javascript, and
> passing different data?
> 
> -cjl
> 
Unless the data you you need depends on the site detecting a specific 
browser you will probably receive a 'cleaner' code that's more easily 
parsed if you don't set a user agent. Usually the browser optimization 
they do is just eye candy, bells and whistles anyway in order to give 
you a more 'pleasing experience'. I doubt that your program will care 
about that ;)

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help to learn Python

2007-03-23 Thread Tina I
PythonBiter wrote:
> Hi everyone,
> 
> I'm very new in this Group as well Python language. I want to learn
> Python. So could you please advice me, and guide me how can i become
> master in Python !
> 
> 
> Thanks,
> Partha
> 
Lots of great resources for beginners: 
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
-- 
http://mail.python.org/mailman/listinfo/python-list


__init__.py

2007-03-25 Thread Tina I
When looking at other peoples code (to learn from it) I keep seeing an 
empty file named "__init__.py". What's the purpose of this?

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __init__.py

2007-03-25 Thread Tina I
Tina I wrote:
> When looking at other peoples code (to learn from it) I keep seeing an 
> empty file named "__init__.py". What's the purpose of this?
> 
> Thanks
> Tina

Duh! Never mind... found it.
Kinda neat actually :)

T
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __init__.py

2007-03-27 Thread Tina I
Jorgen Grahn wrote:
> On Mon, 26 Mar 2007 08:27:19 +0200, Tina I <[EMAIL PROTECTED]> wrote:
>> Tina I wrote:
>>> When looking at other peoples code (to learn from it) I keep seeing an 
>>> empty file named "__init__.py". What's the purpose of this?
>>>
>>> Thanks
>>> Tina
>> Duh! Never mind... found it.
>> Kinda neat actually :)
> 
> /What/ was neat? It's polite in cases like this to explain what the
> answer or solution was.
> 
> I have never seen an empty __init__.py, and I'd like to know what its
> purpose could be.
> 
> BR,
> /Jorgen
> 
Sorry, it was just that it was so easy to find right there in the 
documentation. I had just missed it the first time around. So I kinda 
assumed that since it was spelled out so well in the doc I was asking a 
very stupid question.
But anyway, it can be found here: 
http://www.python.org/doc/2.1.3/tut/node8.html#SECTION00840

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Append data to a list within a dict

2007-04-13 Thread Tina I
Hello group,

Say I have the following dictionary:

ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I can't 
figure out how to that?
Some pointers would be greatly appreciated.

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Append data to a list within a dict

2007-04-13 Thread Tina I
Paul Rubin wrote:
> Tina I <[EMAIL PROTECTED]> writes:
>> ListDict = {
>> 'one' : ['oneone' , 'onetwo' , 'onethree'],
>> 'two' : ['twoone' , 'twotwo', 'twothree'],
>> 'three' : ['threeone' , 'threetwo', threethree']}
>>
>> Now I want to append 'twofour' to the list of the 'two' key but I
>> can't figure out how to that?
> 
> Is this a class exercise?  Hint:
>   1) figure out how to access the list of the 'two' key
>   2) append 'twofour' to it.
He he... at the age of 40 I'm well beyond school work ;)
But thanks anyway

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Append data to a list within a dict

2007-04-13 Thread Tina I
Michael Bentley wrote:
> 
> On Apr 14, 2007, at 12:39 AM, Tina I wrote:
> 
>> Say I have the following dictionary:
>>
>> ListDict = {
>> 'one' : ['oneone' , 'onetwo' , 'onethree'],
>> 'two' : ['twoone' , 'twotwo', 'twothree'],
>> 'three' : ['threeone' , 'threetwo', threethree']}
>>
>> Now I want to append 'twofour' to the list of the 'two' key but I can't
>> figure out how to that?
>> Some pointers would be greatly appreciated.
> 
> ListDict['two'].append('twofour')
> 
> But you'll have to insert the missing single quote before "threethree" 
> first.
> 
> hope this helps,
> Michael
Great! Thanks!
And the missing singlequote was just a typo, my actual dictionary is way 
bigger so I just made up this as an example.

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Append data to a list within a dict

2007-04-15 Thread Tina I
Alex Martelli wrote:
> Tina I <[EMAIL PROTECTED]> wrote:
>...
>> He he... at the age of 40 I'm well beyond school work ;)
> 
> Why would that be?  My wife's over 40, yet she's a student (currently at
> Stanford -- they were overjoyed to admit her, with lot of life
> experience as well as previous studies, apparently).  She's not taking
> elementary courses on Python (having co-written a book on Python,
> tech-reviewed a few, and having been the first woman coopted as a member
> of the PSF:-), but she _has_ been taken equivalent ones on Java and C++
> (languages she didn't previously know), as well as calculus,
> neurophysiology, and other strange things that are part of the "Symbolic
> Systems" studies.
> 
> Down with ageism!-)
> 
> 
> Alex
>  
It's not really ageism, just how I feel *my self* about going back to 
school. I'm not done learning though, it's just that I can give my self 
the luxury of learning whatever I want, just what I want at the pace 
that I want. And since I happen to like computers that's mostly what I 
concentrate about. Right now I'm hooked on Python, but also messing 
about with PHP and Javascript. Tried some Java but didn't like it... 
Threw out Windows a couple of years ago and have spent quite some time 
learning the ins and outs of Linux.

So even if I probably will never go back to school I'm looking forward 
to many many years learning new and exciting things :)

Tina
(Sorry for the way OT post. I just couldn't stop my own ramble ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What makes an iterator an iterator?

2007-04-17 Thread I V
On Wed, 18 Apr 2007 15:39:22 +1000, Steven D'Aprano wrote:
> I thought that an iterator was any object that follows the iterator
> protocol, that is, it has a next() method and an __iter__() method.
...
> class Parrot(object):
...
> def __init__(self):
> self.next = self._next()

self.next isn't a method here, it's a generator. You could do:

def __init__(self):
  self.next = self._next().next

But, having tested, that doesn't appear to work either - I think
this is because, again, self.next is not strictly a method, it's an
attribute that happens to be callable.

The python manual gives you a possible solution:

---QUOTE http://docs.python.org/lib/typeiter.html ---
Python's generators provide a convenient way to implement the iterator
protocol. If a container object's __iter__() method is implemented as a
generator, it will automatically return an iterator object (technically, a
generator object) supplying the __iter__() and next() methods.
---END QUOTE---

i.e., just rename your _next function to __iter__ . Your class won't
itself be an iterator, but it will be usable in for statements and so one,
and convertable to an iterator with the iter builtin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl - SOLVED

2007-09-14 Thread I V
On Thu, 13 Sep 2007 23:49:32 -0400, Amer Neely wrote:
> In trying to track down why this script would not run on my host, it has
> to come to light that Python is installed, however the Apache module is
> not. So, short story is - I was flogging a dead horse.

Which Apache module? You don't need any special modules (just the regular 
CGI one) to use python in a CGI script.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: find and remove "\" character from string

2007-09-15 Thread I V
On Sat, 15 Sep 2007 19:34:45 +0300, Konstantinos Pachopoulos wrote:
> Hi,
> i have the following string s and the following code, which doesn't
> successfully remove the "\", but sucessfully removes the "\\".

There is no \\ in the string; there's one \ , which gets succesfully 
removed.

>  >>> s="Sad\\asd\asd"

When you write a string in the source code \\ gets changed to \ and \a 
gets changed to "ASCII Bell (BEL)" (that's what the docs say), which is a 
(non-printable) control code that is supposed to make the terminal beep.

>  >>> newS=""
>  >>> for i in s:
> ... if i!="\\":

Here, your test is true if i is not \

> ... newS=newS+i
> ...
>  >>> newS
> 'Sadasd\x07sd'

And here, you have a string containing no backslashes, but containing a 
character with ASCII code 7; it turns out that ASCII code 7 is the "ASCII 
Bell", i.e., the character that you added to the string when you wrote 
'\a'.
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt: QListviewItemIterator

2007-01-16 Thread Tina I
Hi,
I'm fairly new to both Python and Qt so please bare with me.

I have a QListView with a number of columns. In order to filter the 
output I iterate using QListViewItemIterator looking for the string 
entered by the user (filterString). Currently I do it this way:


it = QListViewItemIterator(self.authListView)
 try:
 while it:
 item = it.current()
 if item.text(0).contains(filterString) or 
item.text(1).contains(filterString) or item.text(2).contains(filterString):
 item.setVisible(1)
 else:
 item.setVisible(0)
 it +=1
 except AttributeError:
 pass


Basically I iterate through the ListView until it goes beyond the list 
and raise an exception, which I catch. It works but to be honest it 
looks and feels ugly; "Do something until it goes wrong"

So, question: How can I know I have reached the last item in the QListView?

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt: QListviewItemIterator

2007-01-16 Thread Tina I
David Boddie wrote:
> 
> When it.current() returns None. You can rewrite what you already
> have like this:
> 
>  it = QListViewItemIterator(self.authListView)
>  while it.current():
>  item = it.current()
>  if item.text(0).contains(filterString) or \
> item.text(1).contains(filterString) or \
> item.text(2).contains(filterString):
> 
>  item.setVisible(1)
>  else:
>  item.setVisible(0)
>  it += 1
> 
> If you don't like calling item.current() twice for some reason,
> you could write this:
> 
>  it = QListViewItemIterator(self.authListView)
>  item = it.current()
>  while item:
>  if item.text(0).contains(filterString) or \
> item.text(1).contains(filterString) or \
> item.text(2).contains(filterString):
> 
>  item.setVisible(1)
>  else:
>  item.setVisible(0)
>  it += 1
>  item = it.current()
> 
> David

Ah, of course!
Thanks!!

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt4 strangeness

2007-01-23 Thread Tina I
I'm trying to 'convert' my self from Qt3 to Qt4 (it rocks!) and one 
thing seem strange:
With Qt3 I usually did "from qt import *", but this does not seem to 
work with Qt4. I have to use "from PyQt4 import QtGui , QtCore" and also 
have to use "QtCore.something".

Like when connecting a button:

self.connect(self.ui.testButton, QtCore.SIGNAL("clicked()"), 
self.doSomething)

Anyone know why this is? Or am I missing something very basic here? (I'm 
still very much a noob I guess)

I'm using the Debian packages by the way.

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt4 strangeness

2007-01-23 Thread Tina I
Phil Thompson wrote:
> The module structure of PyQt reflects the library structure of Qt. Qt4 has 
> different libraries to Qt3 so PyQt4 has different modules to PyQt3.
> 
> The top level PyQt4 module ensures that PyQt3, PyQt4 (and eventually PyQt5) 
> can all be installed side by side in the same site-packages directory.
> 
> The style of import statement you use is up to you. All of the PyQt4 examples 
> adopt the style you describe, but you can achieve the equivalent of your 
> current practice by doing the following instead...
> 
> from PyQt4.Qt import *
> 
> Phil
Ah, I see :)
Thanks for the explanation.

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Prefered install method?

2007-01-25 Thread Tina I
Another noob question:
I have written my first linux application that might actually be of 
interest to others. Just for fun I also wrote an install script that put 
the files in the common directories for my distro (Debian). That is in 
/usr/local/. (This particular program can be run directly from the 
user's /home but as a learning experience I want to do it the 'coorect' way)

Now, I don't know if that is the way to do it with python applications. 
I also don't know if a custom install script is the norm. I have seen 
some use of makefiles and tried to find something about it but the 
manual for GNUMake really assume you are familiar with/ using C which 
I'm not. I have googled a lot for this but can't really find anything 
aimed for someone just learning programming with Python.

So my question is; What is the preferred/ common way to install a python 
application so it's not really distro specific? And are there any good 
resources on this on the web?

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prefered install method?

2007-01-26 Thread Tina I
Diez B. Roggisch wrote:
> These days, it's setuptools. Google for it. It will let you distribute 
> your application in a convenient way as so-called EGG (basically a 
> ZIP-file), additionally you will get support for installing scripts in 
> /usr/bin or wherever you like, and you have versioning support.
> 
> If you plan to release the app publically, it will also handle the 
> upload to the PyPI, the python package index - also known(?) as cheeseshop.
> 
> Diez

Great! Obviously exactly what I'm looking for. I already had it 
installed even, and it seem to be quite well documented and noob friendly.

Thanks :)
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: emulate a serial port in windows (create a virtual 'com' port)

2007-01-31 Thread Bas-i
On Jan 30, 7:34 am, Pom <[EMAIL PROTECTED]> wrote:

> how can I emulate a serial port in windows?

Google for ComEmulDrv3

This may do what you want.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling J from Python

2007-02-07 Thread Tina I
Gosi wrote:
> On Feb 7, 3:46 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> In <[EMAIL PROTECTED]>, Gosi wrote:
>>> I like to use J for many things and I think that combining Python and
>>> J is a hell of a good mixture.
>> I was able to follow this sentence up to and including the word "hell"...  
>> :-)
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
> 
> 
> That is a start.
> 
> "Hell" is also what most example start with as in "Hello something"
> Hell in northern countries is very cold.
> Hell in middle east is very hot.
> I do not know which is your Hell hot or cold.
> Hell o veröld
> 
It's also a village in Norway: http://en.wikipedia.org/wiki/Hell,_Norway
:D
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling J from Python

2007-02-08 Thread Tina I
Hendrik van Rooyen wrote:
> 
>  I am under the impression that Loki had a daughter called Hel ...
> 
> - Hendrik
> 
Yes. And Hel was the queen of the underworld which was also called 'Hel' 
(Which of course is 'hell', in modern Norwegian : "helvete")

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Question

2007-02-08 Thread Tina I
azrael wrote:
> but look out for pyqt. there is one thing in the eula i don't like.
> there is written that if you use qtWidgets and they like the
> aplication, you have to give up all your rights of the aplication.
> patent, idea, money everything is gone. i know this is open source,
> but maybe one day i will manage to sell an apliction for big money.

That is not exactly correct. Both PyQt and Qt it self is available under 
two different licenses. The GPL versions require that your applications 
has to be released as free software compatible with the GPL. Development 
of commercial closed source applications require a commercial license.

In reality you are free to sell your application as long as it remain 
free (as in freedom) and open source (some argues this is impossible and 
some argue it's no problem. Decide for your self). By nature a GPL'ed 
application can not be patented or even contain patented code as this 
violates the freedom part of the License.

But you have a point though: Always read the license, terms and 
conditions for the tools you want to use. It can really save you some 
serious trouble.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: interacting with shell - another newbie question

2007-02-10 Thread Tina I
James wrote:
> Hello,
> 
> I work in this annoying company where I have to autheticate myself to
> the company firewall every 30-50 minutes in order to access the
> internet.  (I think it's a checkpoint fw).
> 
> I have to run "telnet what.ever.ip.address 259" then it prompts me
> with userid, then password, then I have to select "1".  Then the
> program closes itself and the internet is enabled.
> 
> I would like to automate this process with Python and run it every 30
> miniutes so I don't have to keep typing in these userid/password
> everytime.  How can this be done?  Is there a module I can use to
> interact with the shell? (I'm running linux)
> 
> Thank you.
> 
> James
> 
Sounds like the perfect way to get fired. To be sure though, remember to 
store your password in clear text ;)
However bizarre the security measures seem it's obviously in place to 
make sure it's *you* sitting at the computer. Scripting the 
authentication process is equal to simply removing it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hacking in python

2007-02-10 Thread Tina I
zefciu wrote:
> enes naci wrote:
>> i would like to know about hacking in python too whether its illegal or
>> not is not the point and anyway it doesn't mean i'm gong to use it.
>>
> 
> If you mean hacking as modyfying the code of interpreter of libraries -
> it is perfectly legal, as Python is Open Source.
> 
> If you mean hacking as cracking into computer systems, then what's the
> difference if it's with Python or anything else.
> 
> If you mean hacking as gaining excellency in programming - then why
> should it be?
> 
> Greets
> zefciu
It's really sad. I saw this poor schmuck on "Want to be a millionaire" 
once. His second question was "What is a hacker?" I don't remember all 
of the alternatives but two of them was "A computer programmer" and 
"Someone illegally using a computer".
He answered 'computer programmer'... guess what was the 'correct one'.

I guess he was lucky though... it could have been the one million question.
-- 
http://mail.python.org/mailman/listinfo/python-list


irclib problems

2007-02-11 Thread Tina I
I'm playing around with the 'irclib' library working with the first 
example at 
http://www.devshed.com/c/a/Python/IRC-on-a-Higher-Level-Concluded/

When copying the example verbatim and running it from a console it works 
flawlessly. It connects to the server, join the channel and sits there 
'forever'...

However, I want to use it in a PyQt application and have done the following.
I have created a module named 'irclibtest.py' that looks like this:

### irclibtest start ###
import irclib
irclib.DEBUG = True

class Conn:
 def __init__(self):
 # Network information
 self.network = '192.x.x.x'
 self.port = 6667
 self.channel = '#test'
 self.nick = 'IRClibt'
 self.name = 'Python Test'

 # Subclass SimpleIRCClient
 class ClientClass ( irclib.SimpleIRCClient ):
 pass

 # Create an instance of ClientClass and connect.
 self.client = ClientClass()
 self.client.connect ( self.network, self.port, self.nick, 
ircname = self.name )
 self.client.connection.join ( self.channel )
##irclibtest end ###

And my main Qt application:

### Main application start ###
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys, irclib
from PyQt4 import QtGui , QtCore
from tircUI import Ui_MainWindow
from irclibtest import Conn

class TircMain(QtGui.QMainWindow , Conn):
 def __init__(self):
 QtGui.QMainWindow.__init__(self )
 Conn.__init__(self)
 self.ui = Ui_MainWindow()
 self.ui.setupUi(self)

 self.connect(self.ui.sendButton, QtCore.SIGNAL("clicked()"), 
self.doSend)

 def doSend(self):
 ''' Just a test to see if I can send to channel'''
 self.client.connection.privmsg('#test' , 'Test text')

if __name__ == "__main__":
 app = QtGui.QApplication(sys.argv)
 f = TircMain()
 f.show()
 sys.exit(app.exec_())
### Main application end ##

The problem is that this pings out (PING timeout). As far as I 
understand it rclib.SimpleIRCClient is supposed to handle PING-PONG with 
the server so I don't understand why it does not in my Qt test, but it 
does 'raw'.
I can send to the channel right up to the point it times out by the way.

Anyone know what I'm missing here?

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pep 3105: the end of print?

2007-02-22 Thread I V
On Tue, 20 Feb 2007 10:46:31 -0800, Beliavsky wrote:
> I think the C and C++ committees also take backwards compatibility
> seriously, in part because they know
> that working programmers will ignore them if they break too much old
> code.

While that's true, C++ compiler vendors, for example, take backwards
compatibility significantly less seriously, it seems to me. A year or so
ago, I tried compiling something I'd written for g++ 2, using a
then-recent-ish g++ 3; it failed spectacularly. Likewise with Visual C++ 6
and a Visual C++ 2005. The suggestion that "working programmers"
will reject python if a major version change introduces some backwards
incompatibilities is not borne out by the experience of any other
language I am aware of.

-- 
http://mail.python.org/mailman/listinfo/python-list


HTML to dictionary

2007-02-27 Thread Tina I
Hi everyone,

I have a small, probably trivial even, problem. I have the following HTML:
> 
>  METAR:
> 
> ENBR 270920Z 0KT  FEW018 02/M01 Q1004 NOSIG
> 
> 
>  short-TAF:
> 
> ENBR 270800Z 270918 VRB05KT  FEW020 SCT040
> 
> 
>  long-TAF:
> 
> ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 SNRA VV010 BECMG 2124 
> 15012KT
> 

I need to make this into a dictionary like this:

dictionary = {"METAR:" : "ENBR 270920Z 0KT  FEW018 02/M01 Q1004 
NOSIG" , "short-TAF:" : "ENBR 270800Z 270918 VRB05KT  FEW020 SCT040" 
, "long-Taf:" : "ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 
SNRA VV010 BECMG 2124 15012KT"}

I have played around with BeautifulSoup but I'm stuck at stripping off 
the tags and chop it up to what I need to put in the dict. If someone 
can offer some hints or example to get me going I would greatly 
appreciate it.

Thanks!
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML to dictionary

2007-02-27 Thread Tina I
Tina I wrote:
> Hi everyone,
> 
> I have a small, probably trivial even, problem. I have the following HTML:
>> 
>>  METAR:
>> 
>> ENBR 270920Z 0KT  FEW018 02/M01 Q1004 NOSIG
>> 
>> 
>>  short-TAF:
>> 
>> ENBR 270800Z 270918 VRB05KT  FEW020 SCT040
>> 
>> 
>>  long-TAF:
>> 
>> ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 SNRA VV010 
>> BECMG 2124 15012KT
>> 
> 
> I need to make this into a dictionary like this:
> 
> dictionary = {"METAR:" : "ENBR 270920Z 0KT  FEW018 02/M01 Q1004 
> NOSIG" , "short-TAF:" : "ENBR 270800Z 270918 VRB05KT  FEW020 SCT040" 
> , "long-Taf:" : "ENBR 271212 VRB05KT 9999 FEW020 BKN030 TEMPO 2012 2000 
> SNRA VV010 BECMG 2124 15012KT"}
> 
> I have played around with BeautifulSoup but I'm stuck at stripping off 
> the tags and chop it up to what I need to put in the dict. If someone 
> can offer some hints or example to get me going I would greatly 
> appreciate it.
> 
> Thanks!
> Tina
Forgot to mention that the "METAR:", "short-TAF", and "long-TAF" is 
always named as such wheras the line of data ("ENBR 271212 VRB05KT  
FEW020 BKN030 TEMPO 2012 2000 SNRA VV010 ") is dynamic and can be 
anything...

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML to dictionary

2007-02-27 Thread Tina I
Thanks people, I learned a lot!! :)

I went for Herbert's solution in my application but I explored, and 
learned from, all of them.

Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt4: Clickable links in QLabel?

2007-03-01 Thread Tina I
Hi everyone,

A short and sweet question: Is it possible to put a clickable link in a 
QLabel that will open in the systems default browser?
I tried to put in some HTML but it did (of course?) simply display the 
code instead of a link. I also tried to set openExternalLinks 'true' but 
then pyuic4 bombed.
I see that QLabel does not have a html text format but I'm still hoping 
it's possible. I really need a link on my main window form.

Thanks
Tina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eof

2007-11-21 Thread I V
On Wed, 21 Nov 2007 17:06:15 -0800, braver wrote:
> Why do I have to count sizes of lines read and compare it to some
> filesize or do other weird tricks just to see, in a way not changing my
> input stream, whether it's at the, well, EOF?

Because you can't, generally, tell whether or not a stream is at the end 
of the file without reading from it; the C standard library doesn't 
guarantee that the EOF status is set until _after_ you've tried to read 
past the end of the file. I don't know, but I suspect that may be why 
python doesn't support querying files for EOF status - the fact that EOF 
can be false when you've read all the data in the file is a source of 
confusion to lots of C programmers.

It looks like ruby internally buffers the stream itself, which is how 
come it can support this. According to the docs:

"Note that IO#eof? reads data to a input buffer."

http://www.ruby-doc.org/core/classes/IO.html#M002309

I'd imagine that's inefficient in a lot of cases; and I don't think it 
provides much benefit. What's the hardship in checking the return values 
of your IO calls? Or iterating over the file, which is a more elegant 
solution in many cases.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] minimalist web server

2007-12-02 Thread I V
On Sat, 01 Dec 2007 19:02:41 -0800, Daniel Fetchinson wrote:
> The reason I need this is that my current best strategy to avoid ads in
> web pages is putting all ad server names into /etc/hosts and stick my
> local ip number next to them (127.0.0.1) so every ad request goes to my
> machine. I run apache which has an empty page for 404 errors so I'll

In this case, do you need a webserver at all? If your browser tries to 
access a web server on 127.0.0.1 and there isn't one, won't the result, 
in most cases, be more or less the same as if the server returned a 404?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a Python person's experience with Ruby

2007-12-08 Thread I V
On Sat, 08 Dec 2007 11:23:57 -0800, MonkeeSage wrote:
>> > The equivalent python idiom is something like:
>>
>> > class A:
>> >   __a = "foo"
>> >   def __init__(self):
>> > self.a = A.__a
[...]
>> > Which roughly translates to this in ruby:
>>
>> > class A
>> >   attr_accessor :a
>> >   def initialize
>> > @a = "foo"
>> >   end
>> > end
[...]
> Not really. In ruby an ivar is accessible within the class *only*, but
> not from without (like a mangled python class var), unless you declare
> an accessor (or write the accessor methods yourself). So my example is
> closer, and is not a WTF, if you know how ruby works.

In your python example, the class attribute is mangled, but the instance 
attribute isn't, whereas your ruby code has no class attribute, and an 
instance attribute that isn't (directly) accessible outside the class. 
The equivalent in python would involve a mangled instance attribute,  
like:

class A(object):
def __init__(self):
self.__a = "foo"
def get_a(self):
return self.__a
def set_a(self, val):
self.__a = val
a = property(get_a, set_a)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a Python person's experience with Ruby

2007-12-09 Thread I V
On Sun, 09 Dec 2007 11:58:05 -0800, MonkeeSage wrote:
> class A
>   attr_accessor :a # == self.a,
># accessible to instances of A
>   def initialize
> @a = "foo" # A.__a
># only accessible from class scope of A
>   end
> end
> 
> Once again, there is no such thing as an attribute that is not a method
> in ruby, and there is no such thing as setting an *attribute* ("=" is a
> method also). You're trying to *re-implement* rubys mechanism in python
> in your example, but in pythons mechanism, all attributes already have
> built-in getter/setter. So the correct analogy is a variable that is
> accessible from within the classes scope only (A.__a), and then exposed
> to instances through an attribute (self.a). Your example leaves out a
> variable accessible only from within the scope of the class, and adds a
> new attribute accessible from the instance (_a).

Either I'm not understanding you, or you're not understanding what A.__a 
means in python. A.__a is a class attribute, not an instance attribute - 
it's equivalent to @@a in ruby, not @a. If I understand what you're 
saying, a better python example to make your point might be:

class A(object):
def __init__(self):
self.__a = "foo" # equivalent to @a
self.a = self.__a # exposes self.__a

Except that this only allows you to access '__a' via the exposed 
attribute 'a', not bind it to a new object. If you do:

inst = A()
inst.a = "bar"

you don't modify inst.__a, unlike the following ruby code, which does 
modify @a .

inst = A.new
inst.a = "bar"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Loops and things

2007-12-14 Thread i . pantusa
On Dec 14, 5:01 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On 2007-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
> > I was wondering how and if it's possible to write a loop in python
> > which updates two or more variables at a time. For instance, something
> > like this in C:
>
> > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) {
> >     printf("i = %d, j = %d\n", i, j);
> > }
>
> > So that I would get:
>
> > i = 0, j = 0
> > i = 1, j = 1
> > i = 2, j = 2
> > ...
> > ...
> > ...
> > i = 9, j = 19
>
> > Can this be done in Python?
>
> Yes, assuming you meant to say:
>
> i = 0, j = 10
> i = 0, j = 11
> ...
> i = 9, j = 19
>
> import sys
> from itertools import izip
>
> for i, j in izip(xrange(10), xrange(10, 20)):
>   sys.stdout.write("i = %d, j = %d\n", (i, j))
>
> --
> Neil Cerutti
> To succeed in the world it is not enough to be stupid, you must also be well-
> mannered. --Voltaire

Yeah, that's what I meant ... ooops :)

Thanks a lot to everyone for the useful info. In the meantime I had
found out about zip and that way of doing it. But I really appreciated
all the different alternative solutions that were illustrated,
especially the more "functional" ones with map ... very cool, I'm also
a big Lisp fan, and I really dig those.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Immutable Geometry Types

2007-12-16 Thread I V
On Sun, 16 Dec 2007 18:13:47 -0800, [EMAIL PROTECTED] wrote:
> I am learning python, having learnt most of my object orientation with
> java, and decided to port some of my geometry classes over. I haven't
> used immutability in python before, so thought this would be an
> interesting chance to learn.
>
> I am looking for feedback on any ways in which I might have left
> variables unprotected, and ways in which I am not being pythonic.

I'm not sure it's pythonic to worry too much about enforcing the 
immutability; and disabling setattr makes the internal attribute setting 
a pain in the arse, for little real gain.

> class Angle (object):

I'm not sure about this, but you might want to make Angle a subclass of 
float ; it would save you re-implementing the comparison operators 
(although you'ld still have to re-implement the arithmetic operators to 
get them to return an Angle instance rather than a float).

> def __init__(self, val, type = 'rad'):
> if type == 'rad':
> super(Angle, self).__setattr__('_value', val)
> else:
> super(Angle, self).__setattr__('_value',
> math.radians(val))

You might want to normalize the angle to between 0 and 2*pi here (though 
you might not, depending on exactly what you want to represent).

Assuming that the user meant degrees in the else branch strikes me as a 
mistake; what if they mis-typed "rad" as "rsd" or something? Better to 
explicitly check, and raise an exception if the value isn't one of 'rad' 
or 'deg'. Another thing you might want to consider is using keyword 
arguments, rather than a string. Like:

def __init__(self, radians=None, degrees=None):
if radians is not None:
self._value = radians
elif degrees is not None:
self._value = math.radians(degrees)
else:
raise TypeError("Angle creation must specify \
keyword argument 'radians' or 'degrees')

Used like:
a = Angle(math.pi) # Uses radians by default
a = Angle(radians=2*math.pi) # Or you can specify it explicitly
a = Angle(degrees=180) # Or specify degrees

> def __setattr__(self, name, value):
> """
> Suppress setting of data - Angle is immutable """
> self._immutableError()
> 
> def __delattr__(self, name):
> """
> Suppress deleting of data - Angle is immutable """
> self._immutableError()

As I say, I wouldn't bother with these, as they make the implementation 
more annoying to no real gain.

> def __add__(self, other):
> if isinstance(other, Angle):
> return Angle(self._value + other._value)
> return NotImplemented

Using 'isinstance' is usually a mistake - rather than checking for type, 
you should just use an object as if it were the correct type and, if 
necessary, deal with the resulting exceptions. This means you can use 
objects of a different type, as long as they have the right interface. 
Here, I'd do:

def __add__(self, other):
return Angle(self.radians + other.radians)

and likewise for __sub__.
 
> def __mul__(self, other):
>     """
> return self * other
> """
> if isinstance(other, Angle):
> return Angle(self._value * other._value)
> return NotImplemented

Leaving aside my earlier point about not checking for types, does it even 
make sense to multiply an angle by another angle? I would have thought 
you multiplied angles by numbers. So just do:

def __mul__(self, other):
return Angle(self._value * other)

And the same for __div__
 

> def fromCos(self, c):
> """
> return angle with specified cos
> """
> return Angle(math.acos(c))
> 
> fromCos = classmethod(fromCos)

You could use decorators here; and the preferred python style for method 
names is all lower case, separated by underscores:

@classmethod
def from_cos(self, c):
return Angle(math.acos(c))

> radians = property(lambda self: self._value, lambda x:
> self._immutableError())

You don't need to explicitly raise an exception in the setter; just don't 
specify a setter function, and attempting to set the property will raise 
an AttributeError.

> DEG_30 = Angle(math.radians(30))

Given that you've gone to the trouble of creating a constructor that will 
take values as degrees, why not use it here?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing interfaces in Python...

2006-04-17 Thread I V

[EMAIL PROTECTED] wrote:
> I see that Python is missing "interfaces". The concept of an interface
> is a key to good programming design in Java, but I've read that they
> aren't really necessary in Python. I am wondering what technique I can
> use in Python to get the same benefits to a program design that I would
> get with interfaces in Java.

To use interfaces in python, just what you would do in Java, except
don't use interfaces.

To expand on that slightly Zen answer, think about why you use
interfaces in Java. The interface declaration tells the compiler that
your object implements a specific set of functions, or that your
function expects an object that implements these functions. Then, at
run time, the actual type of the object is used to decide what function
to call.

However, python doesn't to any type checking at compile time, so it
just uses the dynamic type of the object to decide what function to
call.

> How would I approach this problem in Python? I think I would use an
> abstract class instead of an interface for IFixable, since Python
> supports multiple inheritance, but I'm not sure this is correct.

Concretely:

class Car:
def fix(self):
   print "Your car is ready, sir"


class Bus:
def fix(self):
print "Your bus is ready, sir"


class Mechanic:
def repair(self, customer, vehicle):
vehicle.fix()
customer.bill()


class Customer:
def bill(self):
print "Ouch, that was expensive"


me = Customer()
my_bus = Bus()
my_car = Car()
m = Mechanic()

m.repair(me, my_bus)
m.repair(me, my_car)

Which gives the output:

Your bus is ready, sir
Ouch, that was expensive
Your car is ready, sir
Ouch, that was expensive

If you try and repair something that can't be fixed:

m.repair(me, me)

you get:

Traceback (most recent call last):
  File "test.py", line 30, in ?
m.repair(me, me)
  File "test.py", line 14, in repair
vehicle.fix()
AttributeError: Customer instance has no attribute 'fix'

Obviously, you don't want this to happen when people use your program.
Java would check this at compile time, but as python doesn't, you can
write a unit test to check that the object's you want to implement the
relevant functions really do.

def is_fixable(obj):
try:
obj.fix
except AttributeError:
return False
return True

assert is_fixable(Car())
assert is_fixable(Bus())
assert not is_fixable(Customer())
assert not is_fixable(Mechanic())

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing interfaces in Python...

2006-04-17 Thread I V
Jonathan Daugherty wrote:
> Except when you need to handle exceptions when those methods don't
> exist.  I think interfaces can definitely be useful.

I think I see what you mean, but that's an odd way to put it.
Typically, you aren't going to handle the exceptions produced by type
errors. Of course, you want some way to test that your code doesn't
have type errors. Static type checking is one way of doing the
requisite testing, unit tests are another, but it's the tests that are
useful, not the interfaces per se. Adding interfaces to python, which
doesn't support static type checking, would be useless IMO.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to determine sequence ordering?

2006-04-28 Thread I V
On Fri, 28 Apr 2006 14:27:00 -0700, nikie wrote:
> Steven Bethard wrote:
> 
>>  >>> L = ['C', 'A', 'D', 'B']
>>  >>> positions = dict((item, i) for i, item in enumerate(L))

Do you need the generator expression here? dict(enumerate(L)) should be
equivalent, no?

> Isn't this bound to be less efficient? I mean, inserting the items into
> a dict is probably O(n log n), which is definitely worse than O(n) for
> searching the list twice. And, of course, it would yield different
> results if 'A' or 'D' are in the list more than once.

Although presumably the dict method might be quicker if you were comparing
the positions a large number of times.

Incidentally, does python have a built-in to do a binary search on a
sorted list? Obviously it's not too tricky to write one, but it would be
nice if there was one implemented in C.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to determine sequence ordering?

2006-04-28 Thread I V
On Fri, 28 Apr 2006 16:39:33 -0700, nikie wrote:
> I V wrote:
>> Do you need the generator expression here? dict(enumerate(L)) should be
>> equivalent, no?
> 
> I think the generator is needed to swap the item and the index.
> dict(enumerate(L)) would yield a dict like {0:'C', 1:'A'...}

Oh, of course, I wasn't paying attention.

>> Incidentally, does python have a built-in to do a binary search on a
>> sorted list? Obviously it's not too tricky to write one, but it would
>> be nice if there was one implemented in C.
> 
> I once read in an algorithm book that it took 10 years from the first
> binary search publication until a correct version was published, so, it
> actually is a bit tricky... Better stick to the bisect module. Don't
> know if it's written in C, though.

Thanks for pointing out the bisect module - that's exactly what I was
looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Why does bufsize=1 not work in subprocess.Popen ?

2006-04-29 Thread I. Myself
I read in the docs that "bufsize=1" causes line buffering.  (for 
subprocess.Popen)

The following tiny program launches an executable file and then receives 
its output.  That works, but I want to
receive each line as it is ouput, not all of the lines at termination, 
which is what is happening.
---
from subprocess import Popen, PIPE
from os import remove, sep

p = Popen("." + sep + "myprogram", stdout=PIPE, bufsize=1)

while(1):
line = p.stdout.readline()   # get next line
print line,
if line.count("terminator"):
break
------
How can I get line buffering?

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does bufsize=1 not work in subprocess.Popen ?

2006-04-29 Thread I. Myself
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, I. Myself wrote:
>
>   
>> I read in the docs that "bufsize=1" causes line buffering.  (for 
>> subprocess.Popen)
>>
>> The following tiny program launches an executable file and then receives 
>> its output.  That works, but I want to
>> receive each line as it is ouput, not all of the lines at termination, 
>> which is what is happening.
>> 
>
> From the Python side you can only control Python's input buffer but not
> the output buffer of the external program you are starting.  I guess that
> programs buffers its output.
>
> Ciao,
>   Marc 'BlackJack' Rintsch
>   
That makes sense.  I remember now that someone told me that Windows 
sends line-by-line only to the screen.  To a pipe it sends buffers full.

Thanks,

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


How can I implement a timeout with subprocess.Popen()?

2006-04-30 Thread I. Myself
I want my Python program to invoke a compiled C program, and capture the 
text output.
Here's a fragment from a program that works, using subprocess.Popen:

p = Popen(execName, stdout=PIPE)
while(1):
line = p.stdout.readline() # get next line
outfile.write(line)
(Then I test for a certain unique phrase in line, and then break 
if it occurs)

The above works fine as long as the target program runs for a little 
while and then stops.  But what if  it does not stop?   It might run 
forever, with or without outputting any lines.  How can I make this 
robust?  The keyword might not occur.  The target might crash.  It might 
run forever, with or without text output.

Thanks,

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Can Python kill a child process that keeps on running?

2006-05-01 Thread I. Myself
Suppose we spawn a child process with Popen.  I'm thinking of an 
executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going 
and going.  Does Python have any way to kill it?

This is not hypothetical; I'm doing it now, and it's working pretty 
well, but I would like to be able to handle this run-on condition.  I'm 
using Windows 2000, but I want my program to be portable to linux.

Thanks

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Python kill a child process that keeps on running?

2006-05-01 Thread I. Myself
Serge Orlov wrote:
> I. Myself wrote:
>   
>> Suppose we spawn a child process with Popen.  I'm thinking of an
>> executable file, like a compiled C program.
>> Suppose it is supposed to run for one minute, but it just keeps going
>> and going.  Does Python have any way to kill it?
>>
>> This is not hypothetical; I'm doing it now, and it's working pretty
>> well, but I would like to be able to handle this run-on condition.  I'm
>> using Windows 2000, but I want my program to be portable to linux.
>> 
>
> On linux it's pretty easy to do, just setup alarm signal. On windows
> it's not so trivial to the point you cannot do it using python.org
> distribution, you will need to poke in low level C API using win32
> extensions or ctypes. AFAIK twisted package <http://twistedmatrix.com>
> has some code to help you. Also take a look at buildbot sources
> <http://buildbot.sf.net> that uses twisted. Buildbot has the same
> problem as you have, it needs to kill run away or non-responding
> processes.
>   
That is bad news.   Thanks anyway; bad news is better than no news.

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Python kill a child process that keeps on running?

2006-05-02 Thread I. Myself
Steve Holden wrote:
> I. Myself wrote:
>> Serge Orlov wrote:
>>
>>> I. Myself wrote:
>>>  
>>>
>>>> Suppose we spawn a child process with Popen.  I'm thinking of an
>>>> executable file, like a compiled C program.
>>>> Suppose it is supposed to run for one minute, but it just keeps going
>>>> and going.  Does Python have any way to kill it?
>>>>
>>>> This is not hypothetical; I'm doing it now, and it's working pretty
>>>> well, but I would like to be able to handle this run-on condition.  
>>>> I'm
>>>> using Windows 2000, but I want my program to be portable to linux.
>>>>
>>>
>>> On linux it's pretty easy to do, just setup alarm signal. On windows
>>> it's not so trivial to the point you cannot do it using python.org
>>> distribution, you will need to poke in low level C API using win32
>>> extensions or ctypes. AFAIK twisted package <http://twistedmatrix.com>
>>> has some code to help you. Also take a look at buildbot sources
>>> <http://buildbot.sf.net> that uses twisted. Buildbot has the same
>>> problem as you have, it needs to kill run away or non-responding
>>> processes.
>>>  
>>
>> That is bad news.   Thanks anyway; bad news is better than no news.
>>
> Note, however, that ctypes is planned to be a part of the 2.5 
> distribution, so while there may not be a platform-independent way to 
> achieve your goals you will at leats be able to do so without external 
> extensions.
I'm an intermediate Python programmer.  Can you explain to me how ctypes 
will let me kill a child process?

Thanks,

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Python kill a child process that keeps on running?

2006-05-03 Thread I. Myself
Dennis Lee Bieber wrote:
> On Tue, 02 May 2006 17:00:42 GMT, "I. Myself" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>   
>> I'm an intermediate Python programmer.  Can you explain to me how ctypes 
>> will let me kill a child process?
>>
>> 
>   ctypes  allows you to call functions within pretty much any DLL file
> (whereas the ActiveState win32api module only calls some core functions)
>   
Ok, I don't know which function to call in which .dll file, but perhaps 
I can find out.   Will ctypes will be a module in Python 2.5?

Thanks

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-05 Thread I V
On Fri, 05 May 2006 17:26:26 -0700, Xah Lee wrote:
> Regarding the lambda in Python situation... conceivably you are right
> that Python lambda is perhaps at best left as it is crippled, or even
> eliminated. However, this is what i want: I want Python literatures,
> and also in Wikipedia, to cease and desist stating that Python supports
> functional programing. (this is not necessarily a bad publicity) And, I

What does lambda have to do with supporting or not supporting functional
programming?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-06 Thread I V
On Sat, 06 May 2006 21:19:58 -0400, Bill Atkins wrote:
> There are also cases where a function is so trivial that the simplest
> way to describe it is with its source code, where giving it a name and
> putting it at the beginning of a function is just distracting and
> time-consuming.  E.g.:
> 
>   (remove-if (lambda (name)
>(find #\- name :test #'char=))   
>  list-of-names)
> 
> What's the sense of giving that function its own name?  It's much
> clearer to simply write it in place.  Yes, it's _possible_ to use
> named functions, but in this case its functionality is so simple that
> it's clearer to simply type it in place.  Why is this expressiveness a
> bad thing, aside from its power to wreck an indentation-significant
> language?

Well, you can do that with python's current,
non-indentation-significance-wrecking, lambda syntax, so I don't think
that's a particularly persuasive example. Note also that the only
limitation python has on where you can define functions is that you can't
define them inside expressions (they have to be statements), so you could
define a named function right before the call to remove-if, which removes
some of the advantage you get from the lambda (that is, the function
definition is not very far from when it's used). 

Actually, I think the limitation on python that is operative here is not
significant whitespace, but the distinction between statements and
expressions.

(crossposts trimmed)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-07 Thread I V
On Sat, 06 May 2006 23:05:59 -0700, Alex Martelli wrote:
> Tomasz Zielonka <[EMAIL PROTECTED]> wrote:
>...
>> higher level languages. There are useful programming techniques, like
>> monadic programming, that are infeasible without anonymous functions.
>> Anonymous functions really add some power to the language.
> 
> Can you give me one example that would be feasible with anonymous
> functions, but is made infeasible by the need to give names to
> functions?  In Python, specifically, extended with whatever fake syntax
> you favour for producing unnamed functions?

Monads are one of those parts of functional programming I've never really
got my head around, but as I understand them, they're a way of
transforming what looks like a sequence of imperative programming
statements that operate on a global state into a sequence of function
calls that pass the state between them.

So, what would be a statement in an imperative language is an anonymous
function that gets added to the monad, and then, when the monad is run,
these functions get executed. The point being, that you have a lot of
small functions (one for each statement) which are likely not to be used
anywhere else, so defining them as named functions would be a bit of a
pain in the arse.

Actually, defining them as unnamed functions via lambdas would be annoying
too, although not as annoying as using named functions - what you really
want is macros, so that what looks like a statement can be interpreted is
a piece of code to be executed later.

Here, for instance, is an article about using scheme (and, in particular,
macros), to produce a fairly elegant monad implementation:

http://okmij.org/ftp/Scheme/monad-in-Scheme.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why _import__ only works from interactive interpreter?

2006-05-07 Thread I V
On Sun, 07 May 2006 16:21:01 -0700, [EMAIL PROTECTED] wrote:
> So, if this is right, I need to put the .py file to be imported inside
> sys.path!! And the relative path will be usedto find the module.
> 
> Can I __import__ providing the absolute path?

>>> import sys
>>> print sys.path
['', '/usr/lib/python24.zip', '/usr/lib/python2.4',
'/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk',
'/usr/lib/python2.4/lib-dynload',
'/usr/local/lib/python2.4/site-packages',
'/usr/lib/python2.4/site-packages',
'/usr/lib/python2.4/site-packages/HTMLgen',
'/usr/lib/python2.4/site-packages/Numeric',
'/usr/lib/python2.4/site-packages/PIL',
'/usr/lib/python2.4/site-packages/cairo',
'/usr/lib/python2.4/site-packages/gst-0.10',
'/usr/lib/python2.4/site-packages/gtk-2.0',
'/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode',
'/usr/lib/site-python'] 

Compare with:

[EMAIL PROTECTED]:~/src/tests$ cat > test.py
import sys
print sys.path
[EMAIL PROTECTED]:~/src/tests$ python test.py
['/home/tim/src/tests', '/usr/lib/python24.zip', '/usr/lib/python2.4',
'/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk',
'/usr/lib/python2.4/lib-dynload',
'/usr/local/lib/python2.4/site-packages',
'/usr/lib/python2.4/site-packages',
'/usr/lib/python2.4/site-packages/HTMLgen',
'/usr/lib/python2.4/site-packages/Numeric',
'/usr/lib/python2.4/site-packages/PIL',
'/usr/lib/python2.4/site-packages/cairo',
'/usr/lib/python2.4/site-packages/gst-0.10',
'/usr/lib/python2.4/site-packages/gtk-2.0',
'/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode',
'/usr/lib/site-python'] 

Note that the first entry in sys.path when run from the interactive
intepreter is a blank string, which doesn't appear in the output from the
script - I assume that's what is allowing the interactive version to
import via an absolute path. I'm not sure if this is the intended
behavior or a bug.

You could make your script work the same way as the interactive
interpreter by doing:

import sys
sys.path.append('')
mod = __import__('/your/absolute/path/module')

But it might be better to just add the particular path:

sys.path.append('/your/absolute/path')
mod = __import__('module')






-- 
http://mail.python.org/mailman/listinfo/python-list


Re: printing out elements in list

2006-05-08 Thread I V
On Mon, 08 May 2006 00:44:39 -0700, micklee74 wrote:
> i have a list with contents like this
> alist = ['>QWER' , 'askfhs', '>REWR' ,'sfsdf' , '>FGDG',
> 'sdfsdgffdgfdg' ]
> 
> how can i "convert" this list into a dictionary such that
> 
> dictionary = { '>QWER':'askfhs' , '>REWR' : 'sfsdf' , '>FGDG',
> 'sdfsdgffdgfdg' }

This strikes me as a little bit voodish, but you could do:

dictionary = dict(zip(alist[::2], alist[1::2]))
-- 
http://mail.python.org/mailman/listinfo/python-list


SciPy - I need an example of use of linalg.lstsq()

2006-05-09 Thread I. Myself
And it has to run on Windows, so it can't use xplt.

I would prefer that it use the simplest multi-dimensional model, z = k + 
a*x1 + b*x2 + c*x3 + d*x4

Anyone have such a thing?

Thanks,

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SciPy - I need an example of use of linalg.lstsq()

2006-05-10 Thread I. Myself
Robert Kern wrote:
> I. Myself wrote:
>   
>> And it has to run on Windows, so it can't use xplt.
>> 
>
> Huh?
>
> A. xplt runs on Windows, too.
> B. xplt has nothing to do with linalg.lstsq().
> C. xplt has been removed from scipy.
>   
Thank you.  I have been misled by the Scipy Tutorial by Travis 
Oliphant.  It has an example which uses xplt; it also mentions that xplt 
is only for x-windows. 

Your example below seems like just what I'm looking for.  I will try it out.

Thanks again.

Mitchell Timin
>   
>> I would prefer that it use the simplest multi-dimensional model, z = k + 
>> a*x1 + b*x2 + c*x3 + d*x4
>> 
>
> In [1]: import numpy as np
>
> In [2]: np.linalg.lstsq?
> Type:   function
> Base Class: 
> String Form:
> Namespace:  Interactive
> File:
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy-0.9.7.2476-py2.4-macosx-10.4-ppc.egg/numpy/linalg/linalg.py
> Definition: np.linalg.lstsq(a, b, rcond=1e-10)
> Docstring:
> returns x,resids,rank,s
> where x minimizes 2-norm(|b - Ax|)
>   resids is the sum square residuals
>   rank is the rank of A
>   s is the rank of the singular values of A in descending order
>
> If b is a matrix then x is also a matrix with corresponding columns.
> If the rank of A is less than the number of columns of A or greater than
> the number of rows, then residuals will be returned as an empty array
> otherwise resids = sum((b-dot(A,x)**2).
> Singular values less than s[0]*rcond are treated as zero.
>
>
> In [3]: z = np.rand(10)
>
> In [4]: x1 = np.rand(10)
>
> In [5]: x2 = np.rand(10)
>
> In [6]: x3 = np.rand(10)
>
> In [7]: x4 = np.rand(10)
>
> In [8]: A = np.column_stack([x1, x2, x3, x4, np.ones(10, float)])
>
> In [9]: A
> Out[9]:
> array([[ 0.07257264,  0.36544251,  0.68467294,  0.3381,  1.],
>[ 0.09520828,  0.27102091,  0.04673061,  0.12905473,  1.],
>[ 0.839834  ,  0.46010114,  0.3949568 ,  0.38983012,  1.],
>[ 0.49776387,  0.70666191,  0.85005579,  0.47738743,  1.],
>[ 0.25457977,  0.93335912,  0.88441593,  0.05255062,  1.],
>[ 0.85982216,  0.97920853,  0.27991214,  0.94230651,  1.],
>[ 0.03224487,  0.1275237 ,  0.66943552,  0.320765  ,  1.],
>[ 0.86807363,  0.63800103,  0.67153924,  0.69125023,  1.],
>[ 0.26571213,  0.68845408,  0.06478114,  0.03657494,  1.],
>[ 0.46615143,  0.99464106,  0.9303421 ,  0.61363703,  1.]])
>
> In [10]: np.linalg.lstsq(A, z)
> Out[10]:
> (array([-0.32421087, -0.23330787,  0.13369118, -0.28334431,  0.84010014]),
>  array([ 0.22958042]),
>  5,
>  array([ 4.59505886,  1.1181838 ,  0.85704672,  0.70211311,  0.4420187 ]))
>
>
> If you have more scipy questions, you will probably want to ask on the
> scipy-user list:
>
>   http://www.scipy.org/Mailing_Lists
>
>   


-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


-- 
http://mail.python.org/mailman/listinfo/python-list


Internet

2008-01-16 Thread i . shoba3
Internet
You are using internet

http://padmagirl.blogspot.com
%
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems getting Python scripts to run on server

2008-01-23 Thread I V
On Wed, 23 Jan 2008 19:41:17 -0800, Yansky wrote:
> Hi, I'm having a lot of problems getting any Python scripts to run on my
> website. I have put them in the cgi-bin directory and chmodded both the
> directory and files to 755. But when I try to access the script, I get a
> 404 error: http://forboden.com/cgi-bin/wp.py

Note that you don't get a 404 error _from the web server_ - you get it 
from wordpress (or at least, I do when I look at your page). So what I 
think is happening is that either the server, or wordpress, doesn't see a 
file at the URL "/cgi-bin/wp.py", and so it thinks your are trying to 
access a wordpress post, and http://forboden.com/cgi-bin/wp.py is getting 
translated to http://forboden.com/index.php/cgi-bin/wp.py . 

I suspect the problem is in the rewrite rules in the .htaccess in your 
root directory. My wordpress installation has these rewrite rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Which, as I understand it mean "not a file" and "not a directory" 
respectively. If your cgi-bin is not in your document root, presumably 
cgi-bin/wp.py will indeed show up as not being a file or directory. I'm 
no mod_rewrite wizard, but looking at the docs[1], maybe you could 
replace those two lines above with:

RewriteCond %{REQUEST_URI} !-U

(thought the docs say this "can impact your server's performance!") I'm 
just guessing at the cause of your problem, but I hope this helps.

[1] http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to make format operator % work with unicode as expected

2008-01-26 Thread I V
On Sun, 27 Jan 2008 05:32:40 +, Peter Pei wrote:
> Yes, it is true that %s already support unicode, and I did not
> contradict that. But it counts the number of bytes instead of
> characters, and makes things like %-20s out of alignment. If you don't
> understand my assertion, please don't argue back and I am only
> interested in answers from those who are qualified.

What version of python are you using? On python 2.4 and 2.5 on linux, 
%-20s counts the characters, not the bytes, or, I think it does. when I 
run:

>>> print u'%-20s|\n%-20s|' % (u'foo bar', u'foo bár')

the output is:

foo bar |
foo bár |

-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   >