Re: Python GUI application embedding a web browser - Options?

2017-10-10 Thread oliver
Can you elaborate what is not sufficient with Qt's web components?
http://doc.qt.io/qt-5/topics-web-content.html. This allows for HTML, CSS,
Javascript, via either native C++ Qt, QML, or Python (PyQt) or mixtures of
these 3. That said, I have not yet used Qt`s web engine so I don`t know how
full-featured it is, how robust, etc. I have used PyQt for several years in
production grade project and it is very solid and well documented and easy
to program with and easy to write tests for.
Oliver

On Mon, 9 Oct 2017 at 12:59 fpp  wrote:

> Paul Moore  said :
>
> > On 9 October 2017 at 04:25,   wrote:
> >> Did you find out the answer for that?
> >
> > Nothing much beyond the pointer to PyQt (which basically said "a lot
> > of the info on the web is out of date" so I should check the latest
> > docs). I didn't take it much further, though, as it was a hobby
> > project and the learning curve for PyQt (any GUI framework, really)
> > was a bit high for the amount of spare time I had at the time.
> >
> > Paul
>
> Have you looked at CEFpython ?
> It seems to work with all major GUIs (Qt, wx, Tk, gtk..)
> https://github.com/cztomczak/cefpython/tree/master/examples
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] Python and Excel

2017-12-18 Thread oliver
That would be amazing. I still have nightmares of when I had to create this
big options analysis VBA program in Excel 2007.

On Mon, Dec 18, 2017, 14:21 MRAB,  wrote:

> Those who use Excel might find this interesting:
>
> Microsoft Considers Adding Python as an Official Scripting Language to
> Excel
>
> https://www.bleepingcomputer.com/news/microsoft/microsoft-considers-adding-python-as-an-official-scripting-language-to-excel/
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple graphic library for beginners

2018-01-10 Thread oliver
Pyqt without hesitation.

   - I've used it in full-fledged desktop app (120k LOC) and it's just
   awesome, so well documented, versatile, and you can learn gradually
   (starting with their simpler tablewidget then later move to their
   tableview/model for added flexibility).
   - Qt is moving so fast into iot and automotive and is so popular on
   desktops, that it's a skill that gets noticed on resumes or in interviews
   (i'm talking from first hand experience).
   - It is available in multiple languages like Java, Go and C#, although I
   have not used those wrappers (the PyQt wrapper is based on sip, whereas
   these other ones are not, so I have no idea about stability etc).
   - the community is huge, there are powerful tools like pytest.qt plugin
   for unit testing GUI, pycharm IDE integrates with it.
   - there is dual license based on LGPL and commercial, with reasonable
   costs, perfect for learning/startup then eventually (if that's the goal
   medium or long term) distribute/sell.

Oliver

On Wed, 10 Jan 2018 at 10:46 bartc  wrote:

> On 10/01/2018 14:55, Antoon Pardon wrote:
> > On 10-01-18 13:40, Jan Erik Moström wrote:
> >> I'm looking for a really easy to use graphic library. The target users
> >> are teachers who have never programmed before and is taking a first
> >> (and possible last) programming course.
> >>
> >> I would like to have the ability to draw lines, circles, etc. Nothing
> >> fancy, as little window management as possible (possible buttons),
> >> perhaps simple events like button presses or clicks on canvas - think:
> >> making simple diagrams or simple figures. Cross-platform
> >>
> >>
> >> Yes, I know about tkinter.
> >>
> >> Yes, I know about various block languages like Scratch but they are
> >> not relevant in this case.
> >>
> >> Any suggestions?
> >>
> >> = jem
> >
> > cairo?
>
> Isn't that output only? (And not necessarily to a screen, but to an
> image or PDF for example.)
>
> So that no interaction is possible.
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Announcement: TLSv1.2 will become mandatory in the future for Python.org Sites

2017-01-13 Thread oliver
When I run this per email from my work laptop,

python3 -c "import urllib.request,json;
print(json.loads(urllib.request.urlopen('
https://www.howsmyssl.com/a/check').read())['tls_version'])"

I get the following traceback:

C:\...>python -c "import urllib.request,json;
print(json.loads(urllib.request.url
w.howsmyssl.com/a/check').read())['tls_version'])"
Traceback (most recent call last):
File "c:\Python35\lib\urllib\request.py", line 1254, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "c:\Python35\lib\http\client.py", line 1106, in request
self._send_request(method, url, body, headers)
File "c:\Python35\lib\http\client.py", line 1151, in _send_request
self.endheaders(body)
File "c:\Python35\lib\http\client.py", line 1102, in endheaders
self._send_output(message_body)
File "c:\Python35\lib\http\client.py", line 934, in _send_output
self.send(msg)
File "c:\Python35\lib\http\client.py", line 877, in send
self.connect()
File "c:\Python35\lib\http\client.py", line 1260, in connect
server_hostname=server_hostname)
File "c:\Python35\lib\ssl.py", line 377, in wrap_socket
_context=self)
File "c:\Python35\lib\ssl.py", line 752, in __init__
self.do_handshake()
File "c:\Python35\lib\ssl.py", line 988, in do_handshake
self._sslobj.do_handshake()
File "c:\Python35\lib\ssl.py", line 633, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
(_ssl.c:645)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in 
File "c:\Python35\lib\urllib\request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "c:\Python35\lib\urllib\request.py", line 466, in open
response = self._open(req, data)
File "c:\Python35\lib\urllib\request.py", line 484, in _open
'_open', req)
File "c:\Python35\lib\urllib\request.py", line 444, in _call_chain
result = func(*args)
File "c:\Python35\lib\urllib\request.py", line 1297, in https_open
context=self._context, check_hostname=self._check_hostname)
File "c:\Python35\lib\urllib\request.py", line 1256, in do_open
raise URLError(err)
urllib.error.URLError: 

Anyone know how to deal with that? When using pip, I get same error, unless
I add "--trusted-host pypi.python.org":

C:\...>pip install nose
Collecting nose
Could not fetch URL https://pypi.python.org/simple/nose/: There was a
problem confirming the ssl certificate: [SSL: CERTIF
LED] certificate verify failed (_ssl.c:645) - skipping
Could not find a version that satisfies the requirement nose (from
versions: )
No matching distribution found for nose

C:\...>pip install nose --trusted-host pypi.python.org
Collecting nose
Downloading nose-1.3.7-py3-none-any.whl (154kB)
100% || 163kB 386kB/s
Installing collected packages: nose
Successfully installed nose-1.3.7


-- 
Oliver
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python in the news

2018-07-25 Thread oliver
Along the same lines but focused on one of the companies mentioned in the
Economist article is one by Bloomberg :
https://www.bloomberg.com/news/articles/2018-06-14/citi-wants-analysts-to-add-python-to-list-of-languages-on-resume

On Mon, Jul 23, 2018, 12:35 Rich Shepard,  wrote:

>The lead article in science section and technology section of this
> week's
> 'The Economist' is about Python:
> <
> https://www.economist.com/science-and-technology/2018/07/21/python-has-brought-computer-programming-to-a-vast-new-audience
> >
>
> Enjoy,
>
> Rich
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver Schoenborn
  || Cloud Application Engineer, Owner || Sentian Software Engineering ||
Ottawa, ON, Canada
  || +1-613-552-4466 (mobile) || @schollii2 (Twitter) || schoenborno (Skype)
  || LinkedIn <https://linkedin.com/in/oliver-schoenborn> || StackOverFlow
<https://stackoverflow.com/users/869951/oliver> || CodeProject
<https://www.codeproject.com/Articles/schollii#Tip> || GitHub
<https://github.com/schollii>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to host python micro-services on windows machine?

2018-12-10 Thread oliver
There are a few options in https://stackoverflow.com/q/7629813/869951, esp
the third answer.

On Mon., Dec. 10, 2018, 02:41 ,  wrote:

> I am developing some micro-services in python. I want to host that
> micro-services on windows machine. For ubuntu I am using Supervisord. What
> should I use for Windows ? Please help
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver Schoenborn
  || Cloud Application Engineer, Owner || Sentian Software Engineering ||
Ottawa, ON, Canada
  || +1-613-552-4466 (mobile) || @schollii2 (Twitter) || schoenborno (Skype)
  || LinkedIn <https://linkedin.com/in/oliver-schoenborn> || StackOverFlow
<https://stackoverflow.com/users/869951/oliver> || CodeProject
<https://www.codeproject.com/Articles/schollii#Tip> || GitHub
<https://github.com/schollii>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to host python micro-services on windows machine?

2018-12-10 Thread oliver
You might also find that
https://www.raymond.cc/blog/keep-application-running-by-automatically-rerun-when-closed/
lists some useful options.

But most solutions I read about for Windows seem to be based on its
Services subsystem and its ability to restart and control how many time to
retry.

On Mon., Dec. 10, 2018, 07:17 oliver,  wrote:

> There are a few options in https://stackoverflow.com/q/7629813/869951,
> esp the third answer.
>
> On Mon., Dec. 10, 2018, 02:41 ,  wrote:
>
>> I am developing some micro-services in python. I want to host that
>> micro-services on windows machine. For ubuntu I am using Supervisord. What
>> should I use for Windows ? Please help
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
> --
> Oliver Schoenborn
>   || Cloud Application Engineer, Owner || Sentian Software Engineering ||
> Ottawa, ON, Canada
>   || +1-613-552-4466 (mobile) || @schollii2 (Twitter) || schoenborno (
> Skype)
>   || LinkedIn <https://linkedin.com/in/oliver-schoenborn> || StackOverFlow
> <https://stackoverflow.com/users/869951/oliver> || CodeProject
> <https://www.codeproject.com/Articles/schollii#Tip> || GitHub
> <https://github.com/schollii>
>
> --
Oliver Schoenborn
  || Cloud Application Engineer, Owner || Sentian Software Engineering ||
Ottawa, ON, Canada
  || +1-613-552-4466 (mobile) || @schollii2 (Twitter) || schoenborno (Skype)
  || LinkedIn <https://linkedin.com/in/oliver-schoenborn> || StackOverFlow
<https://stackoverflow.com/users/869951/oliver> || CodeProject
<https://www.codeproject.com/Articles/schollii#Tip> || GitHub
<https://github.com/schollii>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing vs subprocess

2019-03-13 Thread oliver
With multiprocessing you can take advantage of multi-core processing as it
launches a separate python interpreter process and communicates with it via
shared memory (at least on windows). The big advantage of multiprocessing
module is that the interaction between processes is much richer than
subprocess: subprocess is limited to pipes (unless you build your own
alternate comms mechanism), whereas multiprocessing takes care of
marshalling python objects and transporting them to the other processes.
This can be huge in some applications, like we were using it to run batch
monte carlo simulations where we needed to pass simulation related
datastructures, would have been a pain with subprocess.


On Tue, Mar 12, 2019 at 12:30 PM Schachner, Joseph <
joseph.schach...@teledyne.com> wrote:

> Re: " My understanding (so far) is that the tradeoff of using
> multiprocessing is that my manager script can not exit until all the work
> processes it starts finish. If one of the worker scripts locks up, this
> could be problematic. Is there a way to use multiprocessing where processes
> are launched independent of the parent (manager) process?"
>
> I just want to point out that subprocess (which uses the operating system
> to start another processes, to run whatever you say - doesn't have to be
> Python running another script, can be an .exe)  does not have that
> restriction.  The subprocess call can be blocking (the caller waits), or
> not.   If not the caller can do whatever it wants including decide not to
> wait forever, and it can even exit.
>
> Of course, if one of the processes you launched is locked up that is a
> problem all by itself, even thought the manager can exit.
>
> --- Joseph S.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Your IDE's?

2019-03-25 Thread oliver
Been using IDEs for 30 years (turbopascal anyone?): by far, PyCharm (used
for 5 years so far). Then VS Code (one year). I still use both. Vs Code is
faster to load, uses less mem and has a simplicity about it that is
appealing.

BUT vscode has similar speed to pycharm once started (actually might even
be slower), and although very capable, is not anything as capable as
pycharm when it comes to refactoring, inspections, configurability,
debugging, find/replace, integration with Git (way better than the 2
leading Git plugins for vs code), and various other capabilities you take
for granted in pycharm like finding unused imports, deep integration with
pytest, and many more.

On Mon., Mar. 25, 2019, 17:41 John Doe,  wrote:

>
> What is your favorite Python IDE?
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Would you be interested in this Python open source project?

2019-10-12 Thread oliver
There are tons of projects that need help, I recommend that instead of
re-inventing the wheel as there are enough choices out there re cicd and
very likely you will find that your goal of 10/90 is unrealistic.

Have a look at codetriage.com, and github has a feature that allows you to
search for projects that need help.

Another major advantage of helping an existing project is that you will be
seeing how others write python code so you will learn best practices faster
(dont kid yourself, if you do it on your own the code you write now you
will find horrible in a year, and you certainly will not be interested in
rewriting it!).

Keep up the good work!

On Wed., Oct. 9, 2019, 08:35 Simon Connah,  wrote:

>
> On 08/10/2019 15:05, Bill Deegan wrote:
> > You might just consider working with the BuildBot project to add support
> > for lighter weight build workers.
> > Re-Re-Re-inventing the wheel is almost always wasted effort.
>
> Buildbot looks good. I'll check to make sure its open source license is
> compatible with the Affero General Public License version 3. On the
> other hand I do have a desire to build something similar myself just to
> get the hang of things like this. Thank you for your reply.
>
> > On Tue, Oct 8, 2019 at 8:33 AM Rhodri James 
> wrote:
> >
> >> On 08/10/2019 11:22, Simon Connah wrote:
> >>> I'm posting this message as a way to gauge interest in the project and
> >>> to see if it is worth moving forward with. There are probably hundreds
> >>> of CI/CD tools out there and many more general devops tools but what I
> >>> want to build is a CI/CD tool that ONLY supports Python 3.6 or greater
> >>> and only runs on one Linux distribution (my preference is Ubuntu). This
> >>> way configuration would be much more simple than the vast majority of
> >>> devops tools which try to support every programming language that is
> >>> popular (or so it seems) on many different Linux distributions and even
> >>> Windows and macOS.
> >>>
> >>> My theory is that if you limit the devops tool to a very limited
> >>> subsection of the available options the system will be easier to
> >>> configure for users, more stable, easier to patch bugs in and generally
> >>> just be a better all around things for Python developers.
> >>>
> >>> I'd love to hear some feedback on the idea.
> >>>
> >> I think your reasoning is sound.  I probably wouldn't make a lot of use
> >> of it, but I live in Embedded Systems land where it's notoriously hard
> >> to do CI off the target silicon.  Other people living in more tractable
> >> problem spaces will probably be more enthusiastic.
> >>
> >> --
> >> Rhodri James *-* Kynesim Ltd
> >> --
> >> https://mail.python.org/mailman/listinfo/python-list
> >>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to create an Excel app that runs Python?

2020-03-24 Thread oliver
Use the win32com library to interact with Excel via COM. Although the
learning curve is a little steeper it's not too bad and works great. I used
this technique to control ARENA with Python through its COM API to run a
whack of simulations (1000-1), then used python to gather the results,
and used win32com from python to finally inject the data into Excel and get
it to generate charts and tables that could be used by stakeholders without
access to python.

Oliver Schoenborn
  || Cloud Application Engineer, Owner || Sentian Cloud Computing Inc.
  || Ottawa, ON, Canada || +1-613-552-4466 (mobile)
  || oli...@sentianse.com




On Tue, Mar 24, 2020 at 7:16 AM  wrote:

> I have the following scenario:
>
> I have created lots of python files that I use to calculate a Cashflow
> model, when I run these files I get a beautiful pandas DataFrame that
> contains my final model. My mission is to show this table to the rest of
> the company in a friendly format ("Excel") and they need to be able to
> generate this table themselves from Excel, using the Python script I
> created ("the idea is that they open an excel file that has some type of
> dashboard and a form that they need to fill in, once they fill it in and
> press "Go" or "Run" or something like that, these parameters will be sent
> to the Python script to generate this final pandas DataFrame. Finally this
> DataFrame needs to be displayed/pasted in the Excel sheet that they
> initially opened)
>
>
> The problems:
>
> The company needs to be able to run this model, but the users, apart from
> me, use Excel and they can't open up a Jupyter notebook or VSC to run the
> code. They can't even install Python on their machines (or at least that is
> not ideal)
>
>
> My Attempts:
>
> I am currently using "xlwings" to run Python within Excel, although it
> requires that the user has Python and xlwings installed and has added the
> xlwings "Addin", which is not an ideal solution at all.
>
> I am thinking about using Dash, I don't know if it is what I need since I
> haven't looked into it that much yet (I have been trying to make it work on
> xlwings first)
>
>
>
> If you have any suggestions on how to do this, I would really appreciate
> that.
>
> Thank you
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


split a string with quoted parts into list

2005-03-10 Thread oliver
hi there

i'm experimanting with imaplib and came across stringts like
(\HasNoChildren) "." "INBOX.Sent Items"
in which the quotes are part of the string.

now i try to convert this into a list. assume the string is in the variable 
f, then i tried
f.split()
but i end up with
['(\\HasNoChildren)', '"."', '"INBOX.Sent', 'Items"']
so due to the sapce in "Sent Items" its is sepearted in two entries, what i 
don't want.

is there another way to convert a string with quoted sub entries into a list 
of strings?

thanks a lot, olli


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


TypeError: object.__init__() takes no parameters

2011-09-08 Thread Oliver
Hello together,

let me be honest with you, I am a poor programmer who can only do
Perl.
I tried to code a program in Perl, but found that another guy already
finished this job in Python.
Unlucky for me, this guy is now CEO of a company, not really
interested in supporting his old code.

If I want to run shapes.py I receive this error message:

=== error message ===

C:\Documents and Settings\mhg\Desktop\palcalc>shapes.py
EE...
==
ERROR: test_fits (__main__.containerTests)
--
Traceback (most recent call last):
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
265, in test_fits
cont = Container()
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
90, in __init__
super(Container, self).__init__(xsize, ysize)
TypeError: object.__init__() takes no parameters

==
ERROR: test_place_bin (__main__.containerTests)
--
Traceback (most recent call last):
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
257, in test_place_bin
cont = Container()
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
90, in __init__
super(Container, self).__init__(xsize, ysize)
TypeError: object.__init__() takes no parameters

--
Ran 5 tests in 0.032s

FAILED (errors=2)

=== end of error message ===

Snippets of source code:

Line 264 - 268

def test_fits(self):
cont = Container()
cont.place_bin(0, 0, 210, 280)
self.assertEqual(False, cont.fits(Rectangle(0, 210, 280,
420)))
self.assertEqual(True, cont.fits(Rectangle(0, 280, 280, 490)))

Line 87 - 93

class Container(object):
"""Container to store  a number of non-overlapping rectangles."""
def __init__(self, xsize=1200, ysize=800):
super(Container, self).__init__(xsize, ysize)
self.rect = Rectangle(0, 0, xsize, ysize)
self.boxes = []
self.last_placement_strategy = 0

Line 254 - 262

class containerTests(unittest.TestCase):
"""Tests for container objects."""
def test_place_bin(self):
cont = Container()
cont.place_bin(0, 0, 40, 40)
self.failUnlessRaises(RuntimeError, cont.place_bin, 0, 0, 40,
40)
cont = Container()
cont.place_bin(0, 0, 210, 280)
self.failUnlessRaises(RuntimeError, cont.place_bin, 0, 210,
280, 420)

I think this is the main function:

if __name__ == '__main__':
unittest.main()

I do not know if I posted what you need to help me, it just would ease
my life a lot. If you need more information please let me know - if
you want you can even be unfriendly to me :)
-- 
http://mail.python.org/mailman/listinfo/python-list


TypeVar single constraint not allowed, why?

2017-05-02 Thread oliver
The documentation for typing.TypeVar gives these two examples:

T = TypeVar('T')  # Can be anything
A = TypeVar('A', str, bytes)  # Must be str or bytes

I was suprised to find out that the following does not work, exception says
that TypeVar is not definable with only one constraint:

A = TypeVar('A', type)  # Must be a type, like class Foo, etc (rather
than an instance of a type)

The TypeVar source code explicitely forbids only one type constraint, what
is the rationale behind this?

For those who wonder, my function parameter expects a type rather than an
instance of a type, and returns a type.

-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeVar single constraint not allowed, why?

2017-05-04 Thread oliver
On Wed, 3 May 2017 at 18:36 Gregory Ewing 
wrote:

> Ned Batchelder wrote:
> > Couldn't you simply annotate it as ": type", without using a TypeVar?
>
> Not if you want to constrain two types to be the same type.
>
>
Exactly! It would be a lot more expressive to write something like (with
Type assumed imported from typing module):

def func(a: type, b: type) -> Tuple[Type(a), Type(b)]:
...

This will not work because a and b are not globals. I could use strings but
this is a hack / language wart as far as I'm concerned (the language should
be extended so we don't have to resort to a lowly string). I suppose I
could do:

def func(a: type, b: type) -> Tuple[TypeVar['a'], TypeVar['b']]:
...

but this is not pythonic (not clean, simple), and too easy to have typo.
Same with forward declarations, where a class references itself in an
annotation: we should not have to resort to a string to express this, very
clunky and hacky.



> --
> Greg
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: type hinting backward compatibility with python 3.0 to 3.4

2017-05-19 Thread oliver
makes sense that the RHS of the equality (deafult value) should be
evaluated before the LHS (arg name + type) but if you hadn't pointed out
that something was not as you expected, i would not have paid attention and
anticipated as you did. Then again RHS vs LHS might have nothing to do with
the reason that the interpreter evaluates in this order :)

On Fri, 19 May 2017 at 21:59 Chris Angelico  wrote:

> On Sat, May 20, 2017 at 11:42 AM, Gregory Ewing
>  wrote:
> > Steve D'Aprano wrote:
> >>
> >> On Fri, 19 May 2017 11:35 pm, Edward Ned Harvey (python) wrote:
> >>
> >>> I *thought* python 3.0 to 3.4 would *ignore* annotations, but it
> >>> doesn't...
> >>
> >>
> >> Why would you think that?
> >
> >
> > Ever since Guido retconned the purpose of annotations to be
> > for static type hinting *only*, it would make more sense for
> > the interpreter to ignore them, or at least not evaluate them
> > immediately at run time (since it would avoid all the problems
> > of forward references, etc).
> >
> > So I can see how someone relying on the principle of least
> > surprise might assume that.
>
> They're function metadata. What would the principle of least surprise
> say about this?
>
> print("Spam")
> def func(arg: print("Foo") = print("Quux")):
> print("Blargh")
> print("Fred")
> func()
> print("Eggs")
>
> What should be printed, and in what order?
>
> Actually, Python does violate least-surprise in one area here. There's
> one message that gets printed "out of order" compared to my
> expectation. I wonder if it's the same one that other people will be
> surprised at.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: type hinting backward compatibility with python 3.0 to 3.4

2017-05-21 Thread oliver
Could something like this support forward declarations without the hackish
use of strings?

On Sun, 21 May 2017 at 12:01 justin walters 
wrote:

> On Sun, May 21, 2017 at 2:38 AM, Chris Angelico  wrote:
>
> > On Sun, May 21, 2017 at 7:29 PM, bartc  wrote:
> > >
> > > They might be /created/ at runtime, but it's a pretty good bet that the
> > name
> > > A in this declaration:
> > >
> > >   class A...
> > >
> > > is the name of a class. The question in Python, as always, is whether
> an
> > A
> > > used as the name of a type in a type, is still this same A. And
> > presumably
> > > such a type hint can precede the declaration of A.
> > >
> > > In fact the declaration of A might be in a different module from its
> use
> > in
> > > a type hint, which means that, in the CPython byte-code compiler
> anyway,
> > it
> > > is not visible at compile-time, when type hints could best be put to
> good
> > > effect.
> >
> > That isn't a problem - mypy follows imports. It'd be pretty useless if
> > it didn't :)
> >
> > > Furthermore, both A, and the type-hinting code, might be conditional.
> So
> > > that on Tuesdays, A is a class, the rest of the week it's the name of a
> > > module.
> >
> > Or, more plausible example: on platforms that have a system-provided
> > source of entropy, random.random is an instance of SystemRandom, but
> > on those that don't, it's an instance of DeterministicRandom with an
> > arbitrarily-chosen seed. The two will have slightly different APIs.
> >
> > > Python doesn't make things easy.
> >
> > Python makes things flexible, which has a cost.
> >
> > ChrisA
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
>
> Perhaps a good way to distinguish between a class that can be used as a
> type and a class
> that cannot be used as a type would be to require some sort of dunder
> method be
> defined on the type class. At first I was thinking `__type__`, but then I
> remembered that's
> already in use. maybe something as simple as `__hint__`.
>
> That or only allow classes that inherit from `type` to be used in type
> annotations.
>
> I'm just spit balling ideas here.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Scala considering significant indentation like Python

2017-05-22 Thread oliver
Any nesting beyond third level should be strong candidate for refactoring.
Soon after you do that, big surprise, refactored block gets better
documented, gets used elsewhere, becomes testable on its own, etc. I.e. if
structure is not obvious from indentation alone, refactoring is the proper
solution, not braces.

Also deeply nested structures tend to involve variables in the deepest
levels that are also used in the outer levels, making the scope of
variables harder to manage (leading to similar bugs as result from use of
global variables).

So languages that do not require braces for code blocks encourage
refactoring, and hence clearer code structure, separation of concerns,
isolation of namespaces, etc.

On Mon, May 22, 2017, 09:31 Cholo Lennon  wrote:

> On 22/05/17 00:53, Steve D'Aprano wrote:
> > The creator of Scala, Martin Odersky, has proposed introducing
> Python-like
> > significant indentation to Scala and getting rid of braces:
> >
> >  I was playing for a while now with ways to make Scala's syntax
> >  indentation-based. I always admired the neatness of Python syntax
> >  and also found that F# has benefited greatly from its optional
> >  indentation-based syntax, so much so that nobody seems to use
> >  the original syntax anymore.
> >
> > https://github.com/lampepfl/dotty/issues/2491
> >
> >
> >
>
>  From the link:
>
> "Impediments
>
> What are the reasons for preferring braces over indentations?
>
> Provide visual clues where constructs end. With pure indentation based
> syntax it is sometimes hard to tell how many levels of indentation are
> terminated at some point... "
>
> I am a huge python fan (but also a C++ and Java fan) and I agree with
> Scala creator, sometimes the readability is complicated. So, more often
> than I would like to, I end up missing the braces :-O
>
>
> --
> Cholo Lennon
> Bs.As.
> ARG
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question

2017-07-31 Thread oliver
On Mon, Jul 31, 2017, 17:33 Sonja Williams via Python-list, <
python-list@python.org> wrote:

>
>
>
>
> Good Day,
>
> I have decided to learn more about programming so I picked up the book
> Beginning Programming by Matt Telles.  After following the directions
> verbatim and going to the Python site to download the latest version 3,
> which is what the book recommended, I keep getting the following error
> message when running my first script. I am using Windows 7 - 64 bit
>
> " python is not recognized as an internal or external command, operable
> program, or batch file".
>
>
> I am at the end of chapter 3 attempting to run the following script.
>
> python ch3_1.py  which should return What is your name?
>
>
> What am I doing wrong?
>

The window in which you are typing the command to run the script is called
a "shell". The error you are getting means the shell does not have a
built-in command (like cd or dir or help) called "python", nor can it
find "python.bat" or "python.exe" in any of the folders known to it. To
check which folders are known to the shell, type "path" in it; the
semicolon-separated list of folders that this prints will likely be missing
the Python folder.

I presume you installed python 3.6? There is an option to add the Python
folder to path as part of the installation, so you might want to uninstall
python, then re-run the installer this time paying close attention to this
configuration option. For example in Python 3.5 installer the option is
called "Add Python 3.5 to path", see the first snapshot at
https://docs.python.org/3/using/windows.html.

With this option in effect, the output from the "path" command will include
the Python folder. So when you type "python ch3.py" the shell will see a
python.exe in Python folder and run it and all will work!

Oliver


>
>
>
>
>
> Sonja Williams
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proposed new syntax

2017-08-10 Thread oliver
Then what about

[x for x in (0, 1, 2, 3, 4, 66, 7, 8, 9, 10)
while x < 10
if x % 2 == 0]

Seems it should be valid and [0, 2, 4].

On Thu, Aug 10, 2017, 14:06 Jussi Piitulainen, <
jussi.piitulai...@helsinki.fi> wrote:

> Steve D'Aprano writes:
>
> > Every few years, the following syntax comes up for discussion, with
> > some people saying it isn't obvious what it would do, and others
> > disagreeing and saying that it is obvious. So I thought I'd do an
> > informal survey.
> >
> > What would you expect this syntax to return?
> >
> > [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5]
>
> [1, 2, 3]
>
> > For comparison, what would you expect this to return? (Without
> > actually trying it, thank you.)
> >
> > [x + 1 for x in (0, 1, 2, 999, 3, 4) if x < 5]
>
> [1, 2, 3, 4, 5]
>
> > How about these?
> >
> > [x + y for x in (0, 1, 2, 999, 3, 4) while x < 5 for y in (100, 200)]
>
> [100, 200, 101, 201, 102, 202]
> >
> > [x + y for x in (0, 1, 2, 999, 3, 4) if x < 5 for y in (100, 200)]
>
> [100, 200, 101, 201, 102, 202, 103, 203, 104, 204]
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-08-14 Thread oliver
It is not a global because accessing an item of a list does not change
whether it is global or local. It would only be global if you declared it
global via a "global" statement. Can you give an example, that would help
determine the issue.

On Mon, 14 Aug 2017 at 16:06 Mok-Kong Shen 
wrote:

> Am 14.08.2017 um 21:53 schrieb Ned Batchelder:
> > On 8/14/17 3:21 PM, Mok-Kong Shen wrote:
> >> Am 14.08.2017 um 20:50 schrieb Ned Batchelder:
> >>> On 8/14/17 2:21 PM, Mok-Kong Shen wrote:
> >>>> I ran the attached program and got the following output:
> >>>>
> >>>> [1, 2, 3]
> >>>> [3, 6, 9]
> >>>>
> >>>> I don't understand why the modification doesn't work in the case of
> >>>> test() but does work in the case of test1().
> >>>>
> >>>> Thanks for your help in advance.
> >>>>
> >>>> M. K. Shen
> >>>>
> >>>> 
> >>>>
> >>>> def test(alist):
> >>>> alist=[3,6,9]
> >>>> return
> >>>>
> >>>> def test1(alist):
> >>>> alist[0],alist[1],alist[2]=3,6,9
> >>>> return
> >>>>
> >>>> ss=[1,2,3]
> >>>> test(ss)
> >>>> print(ss)
> >>>> test1(ss)
> >>>> print(ss)
> >>>
> >>> This reassigns the name alist:  alist = [3, 6, 9].   That changes the
> >>> local variable, but cannot affect the caller's variables.
> >>>
> >>> This leaves alist as the same object, but reassigns its elements,
> >>> mutating the list:  alist[0] = 3
> >>>
> >>> This talk has more details: https://nedbatchelder.com/text/names1.html
> >>
> >> I could more or less understand that in test() alist is interpreted as
> >> local but in the extended program below in test2() I first write the
> >> same as in test1(), after which I logically assume that the name alist
> >> is now known as global and then I write alist=[30,60,90] but that
> >> doesn't have any effect globally, since I get the output:
> >>
> >> [1, 2, 3]
> >> [3, 6, 9]
> >> [3, 6, 9]
> >>
> >> Could you please explain that?
> >>
> >> M. K. Shen
> >> -
> >>
> >> def test(alist):
> >>alist=[3,6,9]
> >>return
> >>
> >> def test1(alist):
> >>alist[0],alist[1],alist[2]=3,6,9
> >>return
> >>
> >> def test2(alist):
> >>alist[0],alist[1],alist[2]=3,6,9
> >>alist=[30,60,90]
> >>return
> >>
> >> ss=[1,2,3]
> >> test(ss)
> >> print(ss)
> >> test1(ss)
> >> print(ss)
> >> test2(ss)
> >> print(ss)
> >
> > Your test2 function first mutates the caller's list by assigning
> > alist[0]=3, then it rebinds the local name alist to be a new list.  So
> > the caller's list is now [3, 6, 9].
>
> Sorry for my poor knowledge. After the line alist[0]..., what is the
> status of the name alist? It's now a global name, right? So why in the
> line following that the name alist would suddenly be interpreted as
> local? I can't yet fully comprehend the logic behind that.
>
> M. K. Shen
>
>
>   .
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re-raised exceptions in 2.7.3 -- stack trace missing

2012-05-14 Thread Oliver Beattie
Hi there

I'm tying to investigate a bit of a weird problem here. Basically, I've just 
upgraded Python (from 2.7.2 -> 2.7.3) by way of an OS upgrade (Ubuntu), and now 
all the tracebacks I'm getting sent from my web app are looking like this:

http://dpaste.org/EgKJp/

As you can see, Django is correctly re-raising the exception, but the original 
stack trace is not there by way of sys.exc_info(). I've dug into the code a 
little and it seems fairly simple, exc_info is passed through logging.error 
from sys.exc_info() so I see no reason why this shouldn't work.

Bit perplexing, any idea what could cause this?

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


Re: Pipe in the "return" statement

2011-07-25 Thread Oliver Bestwalter
Hello Archard,

On 25.07.2011, at 16:16, Archard Lias wrote:

> On Jul 25, 2:03 pm, Ian Collins  wrote:
>> On 07/26/11 12:00 AM, Archard Lias wrote:
>> 
>>> Hi,
>> 
>>> Still I dont get how I am supposed to understand the pipe and its task/
>>> idea/influece on control flow, of:
>>> return  |
>>> ??
>> 
>> It's simply a bitwise OR.
>> 
>> --
>> Ian Collins
> 
> Yes, but how does it get determined, which one actually gets returned?

You do a Bitwise OR with numbers. Your statements are both returning numbers 
and those are combined with a bitwise OR. Combining b0001 with b0010 results in 
0011 for example, you can see this very often done in C Code to set and check 
flags. Here is a gentle introduction:

http://www.codeproject.com/KB/tips/Binary_Guide.aspxhttp://www.codeproject.com/KB/tips/Binary_Guide.aspx

Cheers
Oliver

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


Re: Single line if statement with a continue

2022-12-18 Thread Tony Oliver
On Saturday, 17 December 2022 at 23:58:11 UTC, avi.e...@gmail.com wrote:
> Is something sort of taboo when using something like a computer language to 
> write a program?

With what else would you write a program?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding the working mechanis of python unary arithmetic operators.

2021-10-02 Thread Tony Oliver
On Saturday, 2 October 2021 at 13:48:39 UTC+1, hongy...@gmail.com wrote:
> On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju...@diegidio.name wrote: 
> > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy...@gmail.com wrote: 
> > > See the following testings: 
> > > 
> > > In [24]: a=3.1415926535897932384626433832795028841971 
> > > In [27]: -a 
> > > Out[27]: -3.141592653589793 
> > You've never heard of floating-point? Double precision has 53 significant 
> > bits of mantissa, corresponding approximately to 16 decimal digits. 
> > 
> >  
> > > In [17]: ~-+1 
> > > Out[17]: 0 
> > << The unary ~ (invert) operator yields the bitwise inversion of its 
> > integer argument. The bitwise inversion of x is defined as -(x+1). It only 
> > applies to integral numbers or to custom objects that override the 
> > __invert__() special method. >> 
> > 
> >  
> > > I'm very puzzled by these operators. Any hints will be highly 
> > > appreciated. 
> > Try and read the proverbial manual: that's truly a fundamental skill...
> Thank you for your explanation. Then what about the following questions?: 
> 
> 1. Should `+' and `-' be classified as binary operators or unary operators?

Both.  See sections 6.6 and 6.7 of the documentation at
https://docs.python.org/3/reference/expressions.html

> As we all know, `a + b', and `a - b' are the normal ways we do basic 
> arithmetic operations. 

Really?  Don't you ever write something like "x = -y"?
Or do you habitually write "x = 0 - y" or "x = 0.0 - y"?

> 2. See the following testings: 
> 
> In [20]: bool(int(True)) 
int(True) -> 1
bool(1) -> True
> Out[20]: True 
> 
> In [21]: bool(~int(True)) 
int(True) -> 1
~1 -> -2
bool(-2) -> True
> Out[21]: True 
> 
> In [22]: bool(~~int(True)) 
int(True) -> 1
~1 -> -2  # these two operations
~(-2) -> 1# cancel each other out
bool(1) -> True
> Out[22]: True 
> 
> In [23]: bool(~~~int(True)) 
Because two consecutive bit-inversions cancel each other out;
this is just a complicated re-statement of operation [21], above
> Out[23]: True 
> 
> In [24]: bool(int(False)) 
int(False) -> 0
bool(0) -> False
> Out[24]: False 
> 
> In [25]: bool(~int(False)) 
int(False) -> 0
~0 -> -1
bool(-1) -> True
> Out[25]: True 
> 
> In [26]: bool(~~int(False)) 
Again, two consecutive inversions cancel each other out
so this is just an over-complicated re-statement of [24]
> Out[26]: False 
> 
> In [27]: bool(~~~int(False)) 
Likewise, this is the equivalent of re-stating [25]
> Out[27]: True 
> 
> Why can’t/shouldn't we get something similar results for both `True' and 
> `False' in the above testings? 

Sorry, I can't parse that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Selenium py3.8+ DepreciationWarnings - where to find doc to update code?

2021-10-13 Thread Tony Oliver


On Wednesday, 13 October 2021 at 16:16:46 UTC+1, jkk wrote:
> Selenium 3.141+ 
> python 3.8+ 
> ubuntu 20.04 or windows 10 
> 
> I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several 
> DepreciationWarnings. 
> 
> Can someone point me to where I can find the documentation that explains how 
> to to remedy these warnings. What are the new preferred coding practices? 
> 
> For example, here is a "DepreciationWarning" that I figured out: 
> 
> py3.6+ 
> from selenium import webdriver 
> browser = browser = webdriver.Firefox() 
> browser.get(url) 
> tables = browser.find_elements_by_tag_name("table") 
> 
> 
> py3.8+ 
> from selenium import webdriver 
> from selenium.webdriver.common.by import By 
> browser = browser = webdriver.Firefox() 
> browser.get(url) 
> tables = browser.find_elements(By.TAG_NAME, "table") 
> or 
> tables = browser.find_elements(By.XPATH, "//table")

I cannot help you with your immediate problem but am intrigued to discover what 
your “browser = browser = “ idiom does that differs from “browser = 
“.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-02 Thread Ben Oliver

On 18-12-31 22:39:04, pritanshsahs...@gmail.com wrote:
why did you kept this name? i want to know the history behind this and 
the name of this snake python.


It's named after Monty Python [0].

[0] https://docs.python.org/3/tutorial/appetite.html


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Nufox : Xul + Python

2005-10-02 Thread Oliver Andrich
I would like to test it, but as soon as I try to execute an example my
browser is guided to connect to 192.168.0.40. First off it is an
non-routeable address and secondly my own too. :))) May be you have to
fix your setup another time.

Best regards,
Oliver

2 Oct 2005 03:40:50 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]>:
> Thank you for testing
> Indeed it is very interesting :-)
>
> I've had some problems with my ports forwarding and no-ip.org.
>
> Here is then the new address :
>
> http://artyprog.dyndns.org:8080
>
> Regards
>
> Betwise, I live in France so the site is close when i'am at work
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about inheritance...

2005-10-22 Thread Oliver Andrich
Hi,

22 Oct 2005 14:40:09 -0700, KraftDiner <[EMAIL PROTECTED]>:
> I have a base class called Shape
> And then classes like Circle, Square, Triangle etc, that inherit from
> Shape:
>
> My quesiton is can a method of the Shape class call a method in Circle,
> or Square etc...?

even there would exist a way to accomplish that, I would suggest to
rethink your class hierachy. Such requirements can show serious design
problems.

Best regards,
Oliver

--
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to separate directory list and file list?

2005-10-23 Thread Oliver Andrich
Hi,

2005/10/23, Gonnasi <[EMAIL PROTECTED]>:
> With
> >glob.glob("*")
>
> or
> >os.listdir(cwd)
>
> I can get a combined file list with directory list, but I just wanna a
> bare file list, no directory list. How to get it?

don't know if it is the best solution, but it looks nice. :)

path = "/home/test"
files = [fn for fn in os.listdir(path) if
os.path.isfile(os.path.join(path, fn))]

This gives you just the list of files in a given directory.

Best regards,
Oliver



--
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Object-Relational Mapping API for Python

2005-11-01 Thread Oliver Andrich
Hi,

if you enjoyed Hibernate or got intrigued by it, go and look into
SQLOject (http://www.sqlobject.org/). And you will be less intrigued by
Hibernate, but will start to really like SQLObject. :)

Best regards,
Oliver
-- Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list

get list of member variables from list of class

2005-01-28 Thread Oliver Eichler
Hi 

what will be the fastest solution to following problem

class a:
  def __init__(self):
self.varA = 0
self.varB = 0
s.o. ...


listA = [a]*10


varA = []
varB = []

for l in listA:
  varA.append(l.varA)
  varB.append(l.varB)
  s.o. ...


I could think of:
[varA.append(l.varA) for l in listA]
[varB.append(l.varB) for l in listA]
s.o. ...

But is this faster? After all I have to iterate over listA several times.

Any better solutions?


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


Python and encodings drives me crazy

2005-06-20 Thread Oliver Andrich
Hi everybody,

I have to write a little skript, that reads some nasty xml formated
files. "Nasty xml formated" means, we have a xml like syntax, no dtd,
use html entities without declaration and so on. A task as I like it.
My task looks like that...

1. read the data from the file.
2. get rid of the html entities
3. parse the stuff to extract the content of two tags.
4. create a new string from the extracted content
5. write it to a cp850 or even better macroman encoded file

Well, step 1 is easy and obvious. Step is solved for me by 

= code =

from htmlentitydefs import entitydefs

html2text = []
for k,v in entitydefs.items():
  if v[0] != "&":
html2text.append(["&"+k+";" , v])
  else:
html2text.append(["&"+k+";", ""])

def remove_html_entities(data):
  for html, char in html2text:
data = apply(string.replace, [data, html, char])
  return data

= code =

Step 3 + 4 also work fine so far. But step 5 drives me completely
crazy, cause I get a lot of nice exception from the codecs module.

Hopefully someone can help me with that. 

If my code for processing the file looks like that:

def process_file(file_name):
  data = codecs.open(file_name, "r", "latin1").read()
  data = remove_html_entities(data) 
  dom = parseString(data)
  print data

I get

Traceback (most recent call last):
  File "ag2blvd.py", line 46, in ?
process_file(file_name)
  File "ag2blvd.py", line 33, in process_file
data = remove_html_entities(data)
  File "ag2blvd.py", line 39, in remove_html_entities
data = apply(string.replace, [data, html, char])
  File "/usr/lib/python2.4/string.py", line 519, in replace
return s.replace(old, new, maxsplit)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position
0: ordinal not in range(128)

I am pretty sure that I have iso-latin-1 files, but after running
through my code everything looks pretty broken. If I remove the call
to remove_html_entities I get

Traceback (most recent call last):
  File "ag2blvd.py", line 46, in ?
process_file(file_name)
  File "ag2blvd.py", line 35, in process_file
print data
UnicodeEncodeError: 'ascii' codec can't encode character u'\x96' in
position 2482: ordinal not in range(128)

And this continues, when I try to write to a file in macroman encoding. 

As I am pretty sure, that I am doing something completely wrong and I
also haven't found a trace in the fantastic cookbook, I like to ask
for help here. :)

I am also pretty sure, that I do something wrong as writing a unicode
string with german umlauts to a macroman file opened via the codecs
module works fine.

Hopefully someone can help me. :)

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://fitheach.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and encodings drives me crazy

2005-06-20 Thread Oliver Andrich
> I know this isn't your question, but why write:
> 
>  > data = apply(string.replace, [data, html, char])
> 
> when you could write
> 
>  data = data.replace(html, char)
> 
> ??

Cause I guess, that I am already blind. Thanks.

Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://fitheach.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sudoku dictionary attack

2005-06-20 Thread Oliver Albrecht
Has some one an sodoku-task-generator?
Here another solutions-ways:
http://www.python-forum.de/viewtopic.php?t=3378

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


Re: Python and encodings drives me crazy

2005-06-20 Thread Oliver Andrich
Well, I narrowed my problem down to writing a macroman or cp850 file
using the codecs module. The rest was basically a misunderstanding
about codecs module and the wrong assumption, that my input data is
iso-latin-1 encode. It is UTF-8 encoded. So, curently I am at the
point where I have my data ready for writing

Does the following code write headline and caption in MacRoman
encoding to the disk? Or better that, is this the way to do it?
headline and caption are both unicode strings.

f = codecs.open(outfilename, "w", "macroman")
f.write(headline)
f.write("\n\n")
f.write(caption)
f.close()

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://fitheach.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and encodings drives me crazy

2005-06-20 Thread Oliver Andrich
2005/6/21, Konstantin Veretennicov <[EMAIL PROTECTED]>:
> It does, as long as headline and caption *can* actually be encoded as
> macroman. After you decode headline from utf-8 it will be unicode and
> not all unicode characters can be mapped to macroman:
> 
> >>> u'\u0160'.encode('utf8')
> '\xc5\xa0'
> >>> u'\u0160'.encode('latin2')
> '\xa9'
> >>> u'\u0160'.encode('macroman')
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "D:\python\2.4\lib\encodings\mac_roman.py", line 18, in encode
> return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\u0160' in 
> position
>  0: character maps to 

Yes, this and the coersion problems Diez mentioned were the problems I
faced. Now I have written a little cleanup method, that removes the
bad characters from the input and finally I guess I have macroman
encoded files. But we will see, as soon as I try to open them on the
Mac. But now I am more or less satisfied, as only 3 obvious files
aren't converted correctly and the other 1000 files are.

Thanks for your hints, tips and so on. Good Night.

Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://fitheach.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CONNCET TO SOAP SERVICE

2005-07-19 Thread Oliver Andrich
Hi,

I am not sure if this addresses your problem, but I access a rich SOAP
based webservice set on a Tomcat Server implemented using Axis with
SOAPpy. We use basic auth as specified in http for access control to
these services.

For me it is enough to create my proxy classes this way.

proxy = SOAPpy.SOAPProxy("http://user:[EMAIL PROTECTED]:8080/axis/services,
"MyService")

Afterwards I have access to the system. 

Bye, Oliver


2005/7/12, Slaheddine Haouel <[EMAIL PROTECTED]>:
>  
>  
> 
> Can you help me plz ? I want to wonnect to SOAP webservices but before I
> must be authentificated on a apache server, I used SOAPpy module but I don't
> know how I can be authentified on the apache server 
> 
>   
> 
> thx 
> 
>   
> 
> Slaheddine Haouel 
> 
> Unilog NORD 
> 
> tél : 03 59 56 60 25 
> 
> tél support  : 03 59 56 60 68 
> 
> Email : [EMAIL PROTECTED] 
> 
>   
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 


-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://fitheach.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP on path module for standard library

2005-07-22 Thread Oliver Andrich
Hi,

2005/7/22, Michael Hoffman <[EMAIL PROTECTED]>:
> What is this Java Path class? I have been STFWing and have found nothing
> on it in the. Indeed if you search for "Java Path class" (with quotes)
> almost half of the pages are this message from Guido. ;)
> 
> Any Java hackers here want to tell us of the wonders of the Java Path
> class? I would be interested in seeing how other OO languages deal with
> paths.

I guess the nearest Java class comparable with path is the File class.

http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html

And as I am a so called Java hacker, I highly appreciate path as a
module for my python projects and in my eyes it is the natural way to
address files/paths. At least it is more natural to me then the os,
os.path, etc. pp. bundle, that has grown over the time.

I would love to see path inside Python's stdlib.

Best regards,
Oliver 

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://fitheach.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SOAPpy and http authentication

2005-08-02 Thread Oliver Andrich
2 Aug 2005 11:38:51 GMT, Lutz Horn <[EMAIL PROTECTED]>:
> On 2005-08-02, Odd-R. <[EMAIL PROTECTED]> wrote:
> > from SOAPpy import WSDL
> > from SOAPpy import URLopener
> > url= ' http://someserver/somewebservice
> > url1 = URLopener.URLopener(username='user',passwd='pass')
> > server=WSDL.Proxy(url1.open(url))
> 
> Is it possible to call WSDL.Proxy with a String? Then you could build
> the URL als http://user:[EMAIL PROTECTED]/somewebservice. This works
> with SOAPpy.SOAPProxy.

Yes, you can actually call it that way, but then the wsdl retrieval is
done using the authentication, but all the service calls are done
without. This is something, that is also puzzling me. So far I can
perfectly live with SOAPProxy, but it would be nice to solve this
puzzle.

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://fitheach.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Jabber client?

2005-09-08 Thread Oliver Andrich
Hi Paul,

take this one. http://xmpppy.sourceforge.net/ It is used inside gajim,
my favorite jabber client. http://gajim.org/ It works like a charm.
And I am also using xmpppy for some monitoring tools, that alert our
admins.

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


exceptions from logging on Windows

2005-09-12 Thread Oliver Eichler
Hi,

I experience several exceptions from python's logging system when using the
rollover feature on Windows.

Traceback (most recent call last):
  File "c:\Python24\lib\logging\handlers.py", line 62, in emit
if self.shouldRollover(record):
  File "c:\Python24\lib\logging\handlers.py", line 132, in shouldRollover
self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file

Googeling revealed that this has been experienced by others, too, however no
workaround or solution has been provided. Is this the latest status on this
topic? Do I miss something?

Thanks for help,

Oliver

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


convert list of tuples into several lists

2005-02-09 Thread Oliver Eichler
Hi,

I can find examples to convert lists into a list of tuples like:

>>> map(None,[1,2,3],[4,5,6])
[(1,4),(2,5),(3,6)]

but how is it done vice versa?

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


Re: convert list of tuples into several lists

2005-02-09 Thread Oliver Eichler
Diez B. Roggisch wrote:

> zip(*[(1,4),(2,5),(3,6)])
> 
Thanks :) I knew it must be simple. The asterics - thing was new to me. 

By the way: What is faster?

this:

z = [(1,4),(2,5),(3,6)
a,b = zip(*[(x[0], x[0]-x[1]) for x in z])

or:

a = []
b = []
for x in z:
  a.append(x[0])
  b.append(x[0]-x[1])

I guess first, isn't it?


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


Re: convert list of tuples into several lists

2005-02-10 Thread Oliver Eichler
Pierre Barbier de Reuille wrote:
> Best answer is : try it :)
> use the "timeit" module (in the standard lib) to do so ...

Ok,

import timeit

s = """\
a,b,c1,c2 = zip(*[(x[2],x[4], x[2]-x[1], x[2] - x[3]) for x in z])
"""

t = timeit.Timer(stmt=s,setup="z = [(1,2,3,4,5)]*1000")
print "%.2f usec/pass" % (100 * t.timeit(number=10)/10)

s ="""\
for x in z:
  a = x[2]
  b = x[4]
  c1 = x[2] - x[1]
  c2 = x[2] - x[3]
"""

t = timeit.Timer(stmt=s,setup="z = [(1,2,3,4,5)]*1000")
print "%.2f usec/pass" % (100 * t.timeit(number=10)/10)

for 30 elements:
[EMAIL PROTECTED]:~/tmp> python test.py
32.90 usec/pass
21.53 usec/pass

for 100 elements:
[EMAIL PROTECTED]:~/tmp> python test.py
103.32 usec/pass
70.91 usec/pass

for 100 elements:
[EMAIL PROTECTED]:~/tmp> python test.py
1435.43 usec/pass
710.55 usec/pass

What do we learn? It might look elegant but it is slow. I guess mainly
because I do the iteration twice with the zip command. The 1000 element run
seems to show what Guido means with "abuse of the argument passing
machinery"

Learned my lesson :)

Thanks to all

Oliver


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


Re: convert list of tuples into several lists

2005-02-10 Thread Oliver Eichler
Pierre Barbier de Reuille wrote:
> 
> Best answer is : try it :)
> use the "timeit" module (in the standard lib) to do so ...

Ok, (a second time. I hope the first post was cancelled as it was false)

import timeit

s = """\
a,b,c1,c2 = zip(*[(x[2],x[4], x[2]-x[1], x[2] - x[3]) for x in z])
"""

t = timeit.Timer(stmt=s,setup="z = [(1,2,3,4,5)]*1000")
print "%.2f usec/pass" % (100 * t.timeit(number=10)/10)

s ="""\
a = []
b = []
c1 = []
c2 = []
for x in z:
  a.append(x[2])
  b.append(x[4])
  c1.append(x[2] - x[1])
  c2.append(x[2] - x[3])
"""

t = timeit.Timer(stmt=s,setup="z = [(1,2,3,4,5)]*1000")
print "%.2f usec/pass" % (100 * t.timeit(number=10)/10)

for 100 elements:
[EMAIL PROTECTED]:~/tmp> python test.py
104.67 usec/pass
180.19 usec/pass

for 1000 elements:
[EMAIL PROTECTED]:~/tmp> python test.py
1432.06 usec/pass
1768.58 usec/pass


What do we learn? The zip-thingy is even faster than the for loop

Learned my lesson :)

Thanks to all

Oliver

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


question on installing python 2.7.2 and tcl 8.5.10 on WinXP

2011-10-02 Thread Lynn Oliver
Hello,

I'm having problems building tcl/tk and python on Windows XP so that both are 
installed correctly.

1. ActivePython 2.7.2.5 works fine on my system but may be implicated in recent 
R6034 runtime errors from users.

2. Python.org 2.7.2 msi binaries install fine, but produce a "tcl wasn't 
installed correctly" runtime error from pyinstaller builds.  

3. I built Python.org 2.7.2 sources using MSVC++ 2008 Express with a lot of 
manual work for the subprocess wrappers. The buildbot tools, which should more 
or less automate that process, did not work for me.

4. I can build tcl/tk 8.5.10 using MinGW/Msys.

5. When I built the tkinter component, I placed the build of tcl/tk where it 
was expected by the build scripts, and VC++ reported that the build was 
successful.  However, if I start python.exe from the build directory, I can't 
import Tkinter (or tkinter).

I feel like I must be missing some basic understanding of how and where things 
are installed; having completed the builds I still don't know how to install 
the resulting files into the correct directories.  

Any suggestions?  

Thanks for your help,
Lynn-- 
http://mail.python.org/mailman/listinfo/python-list


httplib or urllib2 tomcat username and password

2006-01-13 Thread Michael Oliver
I am trying to write a Python client to access a Tomcat servlet using Tomcat
Realm authentication with no success.

 

I can use the httplib to connect to localhost port 8080 ok and post and get
and all that is fine, but when I try to set username and password and access
a protected part of tomcat it fails with an Unauthorized.

 

Does anyone have an example of connecting to Tomcat using the Tomcat Realm
(.i.e. tomcat-users.xml) authentication?

I have also tried urllib2 and the example in the header comments still gives
me a HTTP Error 401: Unauthorized when I try to open
http://localhost:8080/slide/



 

Thanks.


 Highly Cohesive and Loosely Coupled

Mike Oliver
CTO Alarius Systems LLC
6800 E. Lake Mead Blvd
Apt 1096
Las Vegas, NV 89156 
[EMAIL PROTECTED]
http://www.alariussystems.com/  tel: 
fax: 
mobile: (702)953-8949 
(702)974-0341
(518)378-6154   

Add me to your address book...   Want a signature like this?

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


Tomcat username and password2

2006-01-13 Thread Michael Oliver
Still trying to get python to access my local tomcat secured with the tomcat
realm

import urllib2
 

 handler = urllib2.HTTPBasicAuthHandler()
 handler.add_password(None,
 'localhost:8080/manager/html', 'root', 'root')
 
 opener = urllib2.build_opener(handler)
 urllib2.install_opener(opener)
 
 try:
 f = urllib2.urlopen( 'http://localhost:8080/manager/html' )
 except urllib2.HTTPError, e:
 if e.code == 401:
 print 'not authorized'
 elif e.code == 404:
 print 'not found'
 elif e.code == 503:
 print 'service unavailable'
 else:
 print 'unknown error: '
 else:
 print 'success'
 for line in f:
 print line,
 

[Mike Oliver>>] this returns 'not authorized' no matter what I put in for
'realm' or 'host' to the add_password() method.  I have tried None, 'tomcat'
for realm and 'localhost' and about every combination I can think of for
'host' if I go to that URL with a browser it asks for username and password
as above and that works.  I can access it with code from PHP or Java just
fine.



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


Python Client accessing Tomcat

2006-01-14 Thread Michael Oliver








I am trying to write a Python client to
access a Tomcat servlet using Tomcat Realm authentication with no success.

 

I can use the httplib to connect to
localhost port 8080 ok and post and get and all that is fine, but when I try to
set username and password and access a protected part of tomcat it fails with
an Unauthorized.

 

Does anyone have an example of connecting
to Tomcat using the Tomcat Realm (.i.e. tomcat-users.xml) authentication?

 

Thanks.

 


 
  
  
   


 
  
  
   




Highly
Cohesive and Loosely Coupled

   
  
  
  
  
   
  
 
 
  
  
   

Mike Oliver
CTO 


Alarius Systems LLC
6800 E. Lake Mead Blvd
Apt 1096
Las Vegas, NV 89156 

   
   

[EMAIL PROTECTED]
http://www.alariussystems.com/




 
  
  tel: 
  fax: 
  mobile: 
  
  
  (702)953-8949 
  (702)974-0341
  (518)378-6154 
  
 



   
  
  
  
 




 

   
  
  
  
 
 
  
  
   

Add me to your address book...


Want a signature like
this?

   
  
  
  
 


 






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

Tomcat authentication from python

2006-01-15 Thread Michael Oliver








I need to access tomcat applications from
python, some are Axis/SOAP web services, and some are file/WebDAV operations.

 

But so far I cannot get python to
authenticate and access http://localhost:8080/manager/html
much less to any of the other applications.

 

I have found examples for httplib with a
base64 Basic Authentication header, and a urllib2 Authentication Handler, but
neither one works.

 

I am not an experienced python developer,
but I am an experienced Java Developer.  I am using PyDev plugin for Eclipse, I
am using Python24.

 

I can connect to tomcat without
authentication for those pages/uri’s that do not require authentication
on that tomcat server, so the problem is with the authentication mechanism in
python.  Obviously I can connect to the entire site and all applications with a
browser and programmatically from Java.

 

Any help greatly appreciated.

 

 


 
  
  
   


 
  
  
   




Highly
Cohesive and Loosely Coupled

   
  
  
  
  
   
  
 
 
  
  
   

Mike Oliver
CTO 


Alarius Systems LLC
6800 E. Lake Mead Blvd
Apt 1096
Las Vegas, NV 89156 

   
   

[EMAIL PROTECTED]
http://www.alariussystems.com/




 
  
  tel: 
  fax: 
  mobile: 
  
  
  (702)953-8949 
  (702)974-0341
  (518)378-6154 
  
 



   
  
  
  
 




 

   
  
  
  
 
 
  
  
   

Add me to your address book...


Want a signature like
this?

   
  
  
  
 


 






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

Re: Re: Ctypes and freeing memory

2006-10-06 Thread Oliver Andrich
On 10/6/06, Thomas Heller <[EMAIL PROTECTED]> wrote:
> Chris Mellon has already pointed out a possible solution, but there is also a
> different way.  You could use a subclass of c_char_p as the restype
> attribute:
>
> class String(c_char_p):
> def __del__(self):
> MagickRelinquishMemory(self)
>
> The difference is that you will receive an instance of this class
> when you call the MagickGetException funcion.  To access the 'char *'
> value, you can access the .value attribute (which is inherited from
> c_char_p), and to free the memory call MagickRelinquishMemory
> in the __del__ method.

These is an even better solution, cause it lets me drop one decorator,
I have been using at the moment, to handle these things.

Thanks a lot. ctypes is so much fun to use. Lately I had to use JNI,
and well, compared to this experience I am now in heaven. :) Sadly, I
can't provide my team members an equal solution in the Java world,
cause one of them starts to hate me for assigning him on another JNI
job in our project.

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: languages with full unicode support

2006-06-25 Thread Oliver Bandel

こんいちわ Xah-Lee san ;-)


Xah Lee wrote:

> Languages with Full Unicode Support
> 
> As far as i know, Java and JavaScript are languages with full, complete
> unicode support. That is, they allow names to be defined using unicode.

Can you explain what you mena with the names here?


> (the JavaScript engine used by FireFox support this)
> 
> As far as i know, here's few other lang's status:
> 
> C → No.

Well, is this (only) a language issue?

On Plan-9 all things seem to be UTF-8 based,
and when you use C for programming, I would think
that C can handle this also.

But I only have read some papers about Plan-9 and did not developed on 
it

Only a try to have a different view on it.

If someone knows more, please let us know :)


Ciao,
Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: languages with full unicode support

2006-06-26 Thread Oliver Wong

"Oliver Bandel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> Xah Lee wrote:
>
>>
>> As far as i know, Java and JavaScript are languages with full, complete
>> unicode support. That is, they allow names to be defined using unicode.
>
> Can you explain what you mena with the names here?

As in variable names, function names, class names, etc.

- Oliver 

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


Re: languages with full unicode support

2006-07-02 Thread Oliver Bandel
Matthias Blume wrote:

> Tin Gherdanarra <[EMAIL PROTECTED]> writes:
> 
> 
>>Oliver Bandel wrote:
>>
>>>こんいちわ Xah-Lee san ;-)
>>
>>Uhm, I'd guess that Xah is Chinese. Be careful
>>with such things in real life; Koreans might
>>beat you up for this. Stay alive!
> 
> 
> And the Japanese might beat him up, too.  For butchering their
> language. :-)

OK, back to ISO-8859-1 :)  no one needs so much symbols,
this is enough: äöüÄÖÜß :)


Ciao,
   Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list

Question about decorators (with context?)

2006-09-24 Thread Oliver Andrich
Hi,

sorry for the vague subject, but I can't come up with a better one so far.

I am currently writing a wrapper around ImageMagicks MagickWand
library using the ctypes module. During this development i have to
handle exceptions in an slightly different way, then python normally
handles them.

I am wrapping the libraries functionality in a class that looks like
that. (I leave out the ctypes calls and stuff as far as it is
possible.)

class MagickWand(object):

def __init__(self):
self._wand = 

@my_funky_decorator
def read_image(self, filename):
return 

You can see, I plan to have my own MagickWand object, which wraps the
C struct and functions. The normal habit of MagickWand is to call a
function, that returns either True or False. Based on this the user
has to check for an exception or not.

I will have to wrap a lot of methods to get all the functionality I
need. And the checking for an exception looks always the same. So I
want to write short methods, which are decorated by my_funky_decorator
which handles the error checking and exception handling. Sadly, this
decorator needs access to self._wand from the current object.

So far I can only think of a solution, where I have to do something like that.

@my_funky_decorator(wand=)
def read_image(self, filename):
pass

So, I like to ask, if someone could enlighten me how to implement the
easy decorator I mentioned in my first "example".

Thanks and best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


ctypes question about call by reference

2006-09-24 Thread Oliver Andrich
Hi,

hopefully someone with some ctypes experience can help me. I guess
this is a trivial task again, but I have been googling, reading,
experimenting the whole afternoon without any success.

I have a given C function signature:

char *MagickGetException(MagickWand *wand,ExceptionType *severity)

- ExceptionType is an enum
- MagickWand is somewhat strange, but so far it works fine without any
type mangling.

How would I wrap this thing using ctypes? Can anybody help me with that?

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: ctypes question about call by reference

2006-09-24 Thread Oliver Andrich
On 9/24/06, Lawrence Oluyede <[EMAIL PROTECTED]> wrote:
> Oliver Andrich <[EMAIL PROTECTED]> wrote:
> > - ExceptionType is an enum
> > - MagickWand is somewhat strange, but so far it works fine without any
> > type mangling.
> >
> > How would I wrap this thing using ctypes? Can anybody help me with that?
>
> First thing first: you have to identify how ExceptionType and MagickWand
> are composed of. Then you can start wrapping them following the
> instructions in the tutorial:
> http://docs.python.org/lib/ctypes-ctypes-tutorial.html

Well, what I learned so far from the documentation, which I already
have read more then once today, is that there is no example for an
enum in this situation. But looking at pygame-sdl and another project,
it looks like the enum is just an c_int or c_long.

And concerning MagickWand, I think I have learned, that I don't need
to define the structure, if I don't want to access it. And I don't
want to, cause this is handled by the library itself. Another point in
this context is also, that it is not defined in the header files
distributed with the library, but only in the source from which the
library is built. As the file is named magick-wand-private.h it is
also not meant to be edited.

Is it at all possbile to use a struct without defining it with ctypes?
Is it okay, to just use the int which is returned by default? Most of
my library works with that configuration, so I thought it is working.

Based on this, can you give me some more hints?

Best regards,
Oliver


-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: ctypes question about call by reference

2006-09-24 Thread Oliver Andrich
After a walk outside, some fresh air around my nose and some time to
relax, I finally found out how to do, what I want to do.

First, define the argument types and the result type.
_dll.MagickGetException.argtypes = (c_long, POINTER(c_long))
_dll.MagickGetException.restype  = c_char_p

Second, write correct code as it is documented. :)

def get_magick_exception(wand):
severity = c_long()
description = _dll.MagickGetException(wand, byref(severity))
return (severity, description)

And thats all. I just did the call to POINTER(c_long) in the wrong
location. Now I do it as documented, and I get everything I want.

I can btw live perfectly without definining what actually a MagickWand
is, cause from the point of the developer just using the library and
documentation, he doesn't know about the actual structure of it. The
definition is hidden the C source of the library, and is not
documented in the public interface.

Thanks and Regards,
Oliver.

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyXML not supported, what to use next?

2006-10-02 Thread Oliver Andrich
Hi PaulOn 9/30/06, Paul Watson <[EMAIL PROTECTED]> wrote:
It would appear that xml.dom.minidom or xml.sax.* might be the bestthing to use since PyXML is going without support.  Best of all it isincluded in the base Python distribution, so no addition hunting required.
Is this right thinking?  Is there a better solution?I am using lxml as my standard tool of choice. It includes the easy interface of ElementTree and the speed and power of being backed by libxml2 and libxslt. But this mainly cause I have to deal with large XMLs in a fast way. Otherwise pure ElementTree is a very, very nice choice. And it is also our "backup" choice, when lxml is not available on a system.
Best regards,Oliver-- Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list

Ctypes and freeing memory

2006-10-03 Thread Oliver Andrich
Hi everybody,

I am currently playing around with ctypes and a C library (libWand
from ImageMagick), and as I want to easily deploy it on Mac, Linux and
Windows, I prefer a ctypes solution over a C module. At least on
windows, I would have resource problems to compile the C module. So,
ctypes is the perfect choice for me.

But I am currently encountering a pattern inside the C library, that
has to be used to free memory. Coding in C I have to do the following

char *description;
long  severity;

description = MagickGetException(wand, &severity);
/*
do something with the description: print it, log it, ...
*/
description = (char *) MagickRelinquishMemory(description);
exit(-1); /* or something else what I want to after an exception occured */

So, this looks easy and is sensible from C's point of view. Now I try
to translate this to Python and ctypes.

dll.MagickGetException.argtypes = [c_long, POINTER(c_long)]
dll.MagickGetException.restype  = c_char_p

severity = c_long()
description = dll.MagickGetException(byref(severity))

# So far so good. The above works like a charm, but the problem follows now
# ctypes already converted the char * for description to a String object.
# That means description has arrived in an area under Python's control.

# these definitions are the easy part
dll.MagickRelinquishMemory.argtypes = [c_void_p]
dll.MagickRelinquishMemory.restype  = c_char_p

# but this obviously must cause problems and causes problems
dll.MagickRelinquishMemory(description)

So, my question is, how do I deal with this situation? Can I ignore
the call to MagickRelinquishMemory, cause Python takes care of the
resources already? Or is it impossible to use it at all, and I have to
think about a different solution?

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Oliver Andrich
Hi,

On 10/3/06, Giovanni Bajo <[EMAIL PROTECTED]> wrote:
> I just read this mail by Brett Cannon:
> http://mail.python.org/pipermail/python-dev/2006-October/069139.html
> where the "PSF infrastracture committee", after weeks of evaluation, 
> recommends
> using a non open source tracker (called JIRA - never heard before of course)
> for Python itself.
>
> Does this smell "Bitkeeper fiasco" to anyone else than me?

No, this doesn't smell like the BK fiasco, it is just the decision to
use a certain tool. But it is easy to change or influence this
recommondation. Step up as an admin for Roundup. :)

Best regards,
Oliver
-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Ctypes and freeing memory

2006-10-03 Thread Oliver Andrich
On 10/3/06, Chris Mellon <[EMAIL PROTECTED]> wrote:
> Not a ctypes expert but I can pretty much guaranteee that Python won't
> correctly release that memory by itself. Are you sure that description
> is actually a string object?

I also think, that Python won't release the memory, and the returned
string isn't helpful either. :)

> If it doesn't, then you can use a more literal translation of the C
> code, and use a c_void_p instead, using ctypes.string_at(description)
> to get a string out of the buffer.

This works and is a great tip! Thanks a lot.

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Image.putpalette(Colors)?

2005-05-17 Thread Oliver Albrecht
 Has somebody a example-script how i can put a other palette to a image?
(after this the image should have similar outlook)


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


Re: Image.putpalette(Colors)?

2005-05-17 Thread Oliver Albrecht
Thanks,
I've read this page.( out of date ?)
http://www.pythonware.com/products/pil/articles/creating-palette-images.htm

Very nicely to become answered  from the major author and python genius
highly personally himself :-D

Which I want to do is; convert several "RGB" Images (or "P") with one
specified palette (to "P").
Or this (for "P")pattern; if the Source Image has the exact same colors but
wrong(other) paletteIds, how can i sort this? With List.sort()?
And give each pixel the right paletteId? That is what i mean with similar
image (source"RGB" to destinaton"P").

convert() without "WEB"?

(sry if i've enough experience with python)>=newbie



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


Re: Image.putpalette(Colors)?

2005-05-17 Thread Oliver Albrecht
I mean equal outlook.
Or  as other objective: give some Images (which has all same colors but
other palettes) for an Animation the same/one palette and nothings is
changed in their outlook


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


Re: Image.putpalette(Colors)?

2005-05-18 Thread Oliver Albrecht
I think in this Example is an fault
lut has the sequence from "im" but not from "lut.putdata(range(256))"

##Getting the Palette Contents Using Resize/Convert
assert im.mode == "P"

lut = im.resize((256, 1))
lut.putdata(range(256))
lut = im.convert("RGB").getdata()
   ^^
# lut now contains a sequence of (r, g, b) tuples

Fredrik Lundh wrote:

> here's one of the first google hits for "PIL putpalette":
>
> http://effbot.org/zone/pil-pseudocolor.htm



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


Re: search/replace in Python

2005-05-27 Thread Oliver Andrich
Hi,

2005/5/28, Vamsee Krishna Gomatam <[EMAIL PROTECTED]>:
> Hello,
> I'm having some problems understanding Regexps in Python. I want
> to replace "PHRASE" with
> "http://www.google.com/search?q=PHRASE>PHRASE" in a block of
> text. How can I achieve this in Python? Sorry for the naive question but
> the documentation is really bad :-(

it is pretty easy and straightforward. After you imported the re
module, you can do the job with re.sub or if you have to do it often,
then you can compile the regex first with re.compile
and afterwards use the sub method of the compiled regex.

The interesting part is

re.sub(r"(.*)",r"http://www.google.com/search?q=\1>\1", text)

cause here the job is done. The first raw string is the regex pattern.
The second one is the target where \1 is replaced by everything
enclosed in () in the first regex.

Here is the output of my ipython session.

In [15]: text="This is a Python. And some random
nonsense test."

In [16]: re.sub(r"(.*)",r"http://www.google.com/search?q=\1>\1", text)

Out[16]: 'This is a http://www.google.com/search?q=Python>Python. And some random
nonsense test.'

Best regards,
Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about wxPython...

2005-05-28 Thread Oliver Albrecht
Helmutt schrieb:
> Whats the name of the event that occur when I press the
> exit/cross-button on the frame?
> How do I connect a function with that event?

Hi,
I try just to begin the same.
I found this in the docu.

wxApp::OnExit
http://wxwidgets.org/manuals/2.5.3/wx_wxapp.html#wxapponexit

wxWindow::Close http://www.wxpython.org/docs/api/wx.Window-class.html#Close

wxCloseEvent
http://www.wxpython.org/docs/api/wx.CloseEvent-class.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Canceling events from COM objects

2007-08-16 Thread Oliver Nelson
I have MapPoint working in Python, and I'm trying to cancel events on 
the map, but I can't seem to make that happen.  I'm responding to the 
events successfully in my panel object.  My code is like this:

global MapPointMod
MapPointMod = 
win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}", 
0, 1, 0)

class MyPanel(wx.Panel):
 def __init__(self, *args, **kwds):
 # begin wxGlade: MyPanel.__init__
 kwds["style"] = wx.TAB_TRAVERSAL
 wx.Panel.__init__(self, *args, **kwds)
 self.frame = args[0]

 MyMap = MakeActiveXClass(MapPointMod.MappointControl, 
eventObj=self)
 self.window_1 = MyMap(self, -1)
 self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
...
...
 def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
 print "tada"


My event fires just fine, but I can't seem to figure out how to cancel 
the event so that mappoint doesn't do its stuff with it...I've tried 
setting Cancel based on the mappoint specs, but it doesn't seem to get 
sent back anywhere...

Any ideas please?

Thanx,

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


Canceling events from COM Objects

2007-08-16 Thread Oliver Nelson
I have MapPoint working in Python, and I'm trying to cancel events on 
the map, but I can't seem to make that happen.  I'm responding to the 
events successfully in my panel object.  My code is like this:

global MapPointMod
MapPointMod = 
win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}", 
0, 1, 0)

class MyPanel(wx.Panel):
 def __init__(self, *args, **kwds):
 # begin wxGlade: MyPanel.__init__
 kwds["style"] = wx.TAB_TRAVERSAL
 wx.Panel.__init__(self, *args, **kwds)
 self.frame = args[0]

 MyMap = MakeActiveXClass(MapPointMod.MappointControl, 
eventObj=self)
 self.window_1 = MyMap(self, -1)
 self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
...
...
 def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
 print "tada"


My event fires just fine, but I can't seem to figure out how to cancel 
the event so that mappoint doesn't do its stuff with it...I've tried 
setting Cancel based on the mappoint specs, but it doesn't seem to get 
sent back anywhere...

Any ideas please?

Thanx,

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


Canceling events from COM Objects

2007-08-16 Thread Oliver Nelson
I have MapPoint working in Python, and I'm trying to cancel events on 
the map, but I can't seem to make that happen.  I'm responding to the 
events successfully in my panel object.  My code is like this:

global MapPointMod
MapPointMod = 
win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}", 
0, 1, 0)

class MyPanel(wx.Panel):
 def __init__(self, *args, **kwds):
 # begin wxGlade: MyPanel.__init__
 kwds["style"] = wx.TAB_TRAVERSAL
 wx.Panel.__init__(self, *args, **kwds)
 self.frame = args[0]

 MyMap = MakeActiveXClass(MapPointMod.MappointControl, 
eventObj=self)
 self.window_1 = MyMap(self, -1)
 self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
...
...
 def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
 print "tada"


My event fires just fine, but I can't seem to figure out how to cancel 
the event so that mappoint doesn't do its stuff with it...I've tried 
setting Cancel based on the mappoint specs, but it doesn't seem to get 
sent back anywhere...

Any ideas please?

Thanx,

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


Events in Com Object for Python

2007-08-16 Thread Oliver Nelson
I have MapPoint working in Python, and I'm trying to cancel events on 
the map, but I can't seem to make that happen.  I'm responding to the 
events successfully in my panel object.  My code is like this:

global MapPointMod
MapPointMod = 
win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}", 
0, 1, 0)

class MyPanel(wx.Panel):
 def __init__(self, *args, **kwds):
 # begin wxGlade: MyPanel.__init__
 kwds["style"] = wx.TAB_TRAVERSAL
 wx.Panel.__init__(self, *args, **kwds)
 self.frame = args[0]

 MyMap = MakeActiveXClass(MapPointMod.MappointControl, 
eventObj=self)
 self.window_1 = MyMap(self, -1)
 self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
...
...
 def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
 print "tada"


My event fires just fine, but I can't seem to figure out how to cancel 
the event so that mappoint doesn't do its stuff with it...I've tried 
setting Cancel based on the mappoint specs, but it doesn't seem to get 
sent back anywhere...

Any ideas please?

Thanx,

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


Cancelling events on a COM Object

2007-08-16 Thread Oliver Nelson
I have MapPoint working in Python, and I'm trying to cancel events on 
the map, but I can't seem to make that happen.  I'm responding to the 
events successfully in my panel object.  My code is like this:

global MapPointMod
MapPointMod = 
win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}", 
0, 1, 0)

class MyPanel(wx.Panel):
 def __init__(self, *args, **kwds):
 # begin wxGlade: MyPanel.__init__
 kwds["style"] = wx.TAB_TRAVERSAL
 wx.Panel.__init__(self, *args, **kwds)
 self.frame = args[0]

 MyMap = MakeActiveXClass(MapPointMod.MappointControl, 
eventObj=self)
 self.window_1 = MyMap(self, -1)
 self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
...
...
 def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
 print "tada"


My event fires just fine, but I can't seem to figure out how to cancel 
the event so that mappoint doesn't do its stuff with it...I've tried 
setting Cancel based on the mappoint specs, but it doesn't seem to get 
sent back anywhere...

Any ideas please?

Thanx,

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


Re: Cancelling events on a COM Object

2007-08-17 Thread Oliver Nelson
James,

I was getting an error everytime so I thought I had a setup problem...

Sorry everybody...

OLIVER

James Stroud wrote:
> Oliver, wait a while before you panic about your post not getting through!
> 
> James
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Canceling events on COM objects

2007-08-18 Thread Oliver Nelson
I have MapPoint working in Python, and I'm trying to cancel events on 
the map, but I can't seem to make that happen.  I'm responding to the 
events successfully in my panel object.  My code is like this:

global MapPointMod
MapPointMod = 
win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}", 
0, 1, 0)

class MyPanel(wx.Panel):
 def __init__(self, *args, **kwds):
 # begin wxGlade: MyPanel.__init__
 kwds["style"] = wx.TAB_TRAVERSAL
 wx.Panel.__init__(self, *args, **kwds)
 self.frame = args[0]

 MyMap = MakeActiveXClass(MapPointMod.MappointControl, 
eventObj=self)
 self.window_1 = MyMap(self, -1)
 self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
...
...
 def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
 print "tada"


My event fires just fine, but I can't seem to figure out how to cancel 
the event so that mappoint doesn't do its stuff with it...I've tried 
setting Cancel based on the mappoint specs, but it doesn't seem to get 
sent back anywhere...

Any ideas please?

Thanx,

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


Re: Canceling events on COM Objects in python

2007-08-18 Thread Oliver Nelson
Mike,

Thank you for the suggestion.  I will ask over there also.  The event is 
sent back from the COM interface as the code illustrates. 
MakeActiveXClass allows me to pass the object that will receive events. 
  I don't understand much more detail about how it works.  It is 
certainly a different model than the standard wx event system...

OLIVER

[EMAIL PROTECTED] wrote:
> On Aug 17, 11:54 pm, Oliver Nelson <[EMAIL PROTECTED]> wrote:
>> I have MapPoint working in Python, and I'm trying to cancel events on
>> the map, but I can't seem to make that happen.  I'm responding to the
>> events successfully in my panel object.  My code is like this:
>>
>> global MapPointMod
>> MapPointMod =
>> win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}",
>> 0, 1, 0)
>>
>> class MyPanel(wx.Panel):
>>  def __init__(self, *args, **kwds):
>>  # begin wxGlade: MyPanel.__init__
>>  kwds["style"] = wx.TAB_TRAVERSAL
>>  wx.Panel.__init__(self, *args, **kwds)
>>  self.frame = args[0]
>>
>>  MyMap = MakeActiveXClass(MapPointMod.MappointControl,
>> eventObj=self)
>>  self.window_1 = MyMap(self, -1)
>>  self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
>> ...
>> ...
>>  def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
>>  print "tada"
>>
>> My event fires just fine, but I can't seem to figure out how to cancel
>> the event so that mappoint doesn't do its stuff with it...I've tried
>> setting Cancel based on the mappoint specs, but it doesn't seem to get
>> sent back anywhere...
>>
>> Any ideas please?
>>
>> Thanx,
>>
>> OLIVER
> 
> This probably isn't the best place to post questions of this nature.
> You should try the wxPython's user group or the pywin32 group.
> 
> http://wxpython.org/maillist.php
> http://mail.python.org/mailman/listinfo/python-win32
> 
> Is the event you're trying to cancel caught by wxPython's event
> handlers or win32?
> 
> Mike
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cancelling events on a COM Object

2007-08-18 Thread Oliver Nelson
Roger,

I tried modifying my code so that I have

def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
print "click"
Cancel = True
return Cancel

But this doesn't seem to have changed anything.  Am I doing this wrong?

OLIVER

Roger Upole wrote:
> Oliver Nelson wrote:
> 
>> I have MapPoint working in Python, and I'm trying to cancel events on the 
>> map, but I can't seem to make that happen.  I'm
>> responding to the events successfully in my panel object.  My code is like 
>> this:
>>
>> global MapPointMod
>> MapPointMod = 
>> win32com.client.gencache.EnsureModule("{51C0A9CA-F7B7-4F5A-96F4-43927C6FA50F}",
>>  0, 1, 0)
>>
>> class MyPanel(wx.Panel):
>> def __init__(self, *args, **kwds):
>> # begin wxGlade: MyPanel.__init__
>> kwds["style"] = wx.TAB_TRAVERSAL
>> wx.Panel.__init__(self, *args, **kwds)
>> self.frame = args[0]
>>
>> MyMap = MakeActiveXClass(MapPointMod.MappointControl, eventObj=self)
>> self.window_1 = MyMap(self, -1)
>> self.window_1.OpenMap("C:\\TEMP\\GPS_ON.ptt")
>> ...
>> ...
>> def OnBeforeClick(self, Button, Shift, X, Y, Cancel):
>> print "tada"
>>
>>
>> My event fires just fine, but I can't seem to figure out how to cancel the 
>> event so that mappoint doesn't do its stuff with
>> it...I've tried setting Cancel based on the mappoint specs, but it doesn't 
>> seem to get sent back anywhere...
>>
>> Any ideas please?
>>
>> Thanx,
>>
>> OLIVER
> 
> Instead of assigning to the variable name, output parameters need to be
> returned from the method
> 
>  Roger
> 
> 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-16 Thread Oliver Bandel
Xah Lee wrote:
> Tabs versus Spaces in Source Code
> 
> Xah Lee, 2006-05-13
> 
> In coding a computer program, there's often the choices of tabs or
> spaces for code indentation. There is a large amount of confusion about
> which is better. It has become what's known as “religious war” —
> a heated fight over trivia. In this essay, i like to explain what is
> the situation behind it, and which is proper.
> 
> Simply put, tabs is proper, and spaces are improper.
[...]

I fullheartedly disagree :)

So, no "essay" on this is necessary to read :->


Ciao,
Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tabs versus Spaces in Source Code

2006-05-16 Thread Oliver Bandel
[EMAIL PROTECTED] opalinski from opalpaweb wrote:

>>Simply put, tabs is proper, and spaces are improper.
>>Why? This may seem
>>ridiculously simple given the de facto ball of confusion: the semantics
>>of tabs is what indenting is about, while, using spaces to align code
>>is a hack.
> 
> 
> The reality of programming practice trumps original intent of tab
> characters.  The tab character and space character are pliable in that
> if their use changes their semantics change.
[...]


Yes, as I started programming I also preferred tabs.
And with growing experience on how to handle this in true life
(different editors/systems/languages...) I saw, that
converting the "so fine tabs" was annoying.

The only thing that always worked were spaces.
Tab: nice idea but makes programming an annoyance.

Ciao,
Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-18 Thread Oliver Bandel
Jonathon McKitrick wrote:

> Pascal Bourguignon wrote:
> 
>>(defun ιοτα (&key (номер 10) (단계 1) (בכוכ 0))
>>  (loop :for i :from בכוכ :to номер :by 단계 :collect i))
> 
> 
> How do you even *enter* these characters?  My browser seems to trap all
> the special character combinations, and I *know* you don't mean
> selecting from a character palette.

Didn't you heard of that big keyboards?

12 meter x 2 meter wide I think you need a long
stick (maybe if you play golf, that can help).

The you have all UTF-8 characters there, that's fine,
but typing needs some time.
But it's good, because when ready with typing your email,
it's not necessary to go to sports after work. So your boss
can insist that you longer stay at work.


Ciao,
Oliver

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

Re: Tabs versus Spaces in Source Code

2006-05-23 Thread Oliver Wong

"Jonathon McKitrick" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Pascal Bourguignon wrote:
>> (defun ιοτα (&key (номер 10) (단계 1) (בכוכ 0))
>>   (loop :for i :from בכוכ :to номер :by 단계 :collect i))
>
> How do you even *enter* these characters?  My browser seems to trap all
> the special character combinations, and I *know* you don't mean
> selecting from a character palette.
>
> ࿿ hey, this is weird...
>
> î
>
> I've got something happening, but I can't tell what.
>
> Yes, I'm an ignorant Western world ASCII user.  :-)

What OS are you using? In Windows XP, you'd have to let the XP know that 
you're interested in input in languages other than English via "Control 
Panel -> Regional Settings -> Languages -> Text Services and Input 
Languages". There, you'd add input methods other than English. Each "input 
method" works in a sort of unique way, so you'll just have to learn them. 
For example, under English, you can use the "keyboard" input method which 
probably is what you're using now, or the "handwriting recognition" input 
method, or the "speech recognition" input method to insert english text. 
There are other input methods for the Asian languages (e.g. Chinese, 
Japanese, etc.)

- Oliver 

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

Custom class to a dictionary?

2008-01-26 Thread Oliver Beattie
Just wondering if it is possible to pass a custom class instance
instance to dict() by way of using methods like you can for iterators
(__iter__, __getitem__ etc.) I see there is no __dict__ -- is there
anything else I can use to achieve this?

Kind Regards,
Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Custom class to a dictionary?

2008-01-26 Thread Oliver Beattie
On Jan 26, 12:01 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sat, 26 Jan 2008 03:35:18 -0800, Oliver Beattie wrote:
> > Just wondering if it is possible to pass a custom class instance
> > instance to dict() by way of using methods like you can for iterators
> > (__iter__, __getitem__ etc.) I see there is no __dict__ -- is there
> > anything else I can use to achieve this?
>
> Just write a method to return (key, value) pairs, and call that:
>
> >>> class Parrot(object):
>
> ...     def __init__(self):
> ...             self.keys = [1, 2, 3, 4]
> ...             self.values = ["one", "two", "three", "four"]
> ...     def generate_tuples(self):
> ...             for k,v in zip(self.keys, self.values):
> ...                     yield (k,v)
> ...>>> p = Parrot()
> >>> p.generate_tuples()
>
> >>> dict(p.generate_tuples())
>
> {1: 'one', 2: 'two', 3: 'three', 4: 'four'}
>
> Here's another way:
>
> >>> class Foo(object):
>
> ...     def __getitem__(self, i):
> ...             if i > 4:
> ...                     raise IndexError
> ...             return (i, 'foo %d' % i)
> ...>>> dict(Foo())
>
> {0: 'foo 0', 1: 'foo 1', 2: 'foo 2', 3: 'foo 3', 4: 'foo 4'}
>
> Bonus marks if you can explain why they both work :)
>
> (Hint: consider the "sequence protocol" and the "iterator protocol".)
>
> --
> Steven

Sure, I get what you're saying here and thanks for the advice; but I
don't want the keys as the iterator indices -- They should have custom
names (latitude, longitude and elevation). Is this possible (outside
of the custom method to generate two-tuples?) Sorry to be a pain!

The class looks like the below; I just whipped this up real quick but
it can generate the iterators it should -- just the dictionaries
should be different -- {'latitude': 0.0, 'longitude': 0.0,
'elevation': 0.0} or whatever):

class Coordinates(object):
"""Basic object for storing co-ordinate data."""
latitude = 0.0
longitude = 0.0
elevation = 0.0

def __unicode__(self):
return u'Coordinate (%s, %s, %s)' % (self.latitude, 
self.longitude,
self.elevation)

def __repr__(self):
return '' % 
(self.latitude,
self.longitude, self.elevation)

def __iter__(self):
return iter((self.latitude, self.longitude, self.elevation))

I guess it's just easier to have a dict() method to this end; just
wondered if there was a more 'Pythonic' way to do this.
-- 
http://mail.python.org/mailman/listinfo/python-list


call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
hi, I'm a Python beginner with a basic question. I'm writing a game
where I have keyboard input handling defined in one class, and command
execution defined in another class. The keyboard handler class
contains a dictionary that maps a key to a command string (like 'h':
'left') and the command handler class contains functions that do the
commands (like def do_right(self):),

I create instances of these classes in a list attached to a third,
'brain' class. What I'd like to have happen is when the player presses
a key, the command string is passed to the command handler, which runs
the function. However I can't figure out a good way to make this
happen.

I've tried a dictionary mapping command strings to functions in the
command handler class, but those dictionary values are evaluated just
once when the class is instantiated. I can create a dictionary in a
separate function in the command handler (like a do_command function)
but creating what could be a big dictionary for each input seems kind
of silly (unless I'm misunderstanding something there).

What would be a good way to make this happen, or is there a different
kind of architecture I should be thinking of?
--
http://mail.python.org/mailman/listinfo/python-list


Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
On May 5, 9:01 am, Chris Rebert  wrote:
> On Tue, May 5, 2009 at 8:52 AM, George Oliver  
> wrote:

> > I create instances of these classes in a list attached to a third,
> > 'brain' class.
>
> You could exploit Python's dynamism by using the getattr() function:


Thanks for the responses -- I should have mentioned that I looked at
the getattr() function, but as I instantiate the key handler and
command handler classes in a list (like handlers = [command_handler(),
keyboard_handler()], I'm unsure how to reference that class instance
in the getattr in a straightforward way (short of keeping track of
each instance's position in the handlers list). Is there a typical way
of doing that?

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


Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
On May 5, 11:59 am, Dave Angel  wrote:

> 1) forget about getattr() unless you have hundreds of methods in your
> map.  The real question is why you need two maps. What good is the
> "command string" doing you?   Why not just map the keyvalues directly
> into function objects?


Thanks for the reply Dave. I understand your example and it's what I
originally used. Here is more detail on what I'm doing now, I hope
this will explain my question better.

In the game I'm writing the player, monsters, items and so on are
instances of class Thing, like:

class Thing(object):
def __init__(self, x, y, name):
self.x, self.y = x, y
self.name = name
self.brain = None

Some Things have an instance of class Brain attached. The Brain
instance has a list of handlers, like:

class Brain(object):
def __init__(self):
self.handlers = []

A handler class defines some functionality for the Brain. Each Brain
has an update method like this:

def update(self, arguments):
for handler in self.handlers:
handler.update(arguments)

So on each pass through the main game loop, it calls the update method
of all the brains in the game, which run their handler update methods
to change the state of the game.

A handler would be something like a key input handler. The key input
handler is defined separately from the command handler in the case I
want to use a different method of input, for example a mouse or
joystick.

In the dictionary of key inputs I could map each input directly to a
function. However there is no instance name I can call the function
on, as I create a thing, add a brain, and add handlers to the brain
like this:

player = Thing(26, 16, 'player')
player.brain = Brain()
player.brain.add_handlers(
commandHandler(player.brain, player),
keyboardHandler(player.brain),
fovHandler(player.brain))


So what I'm wondering is how to reference the instance in each brain's
list of handlers when I want to map something like a key input to a
command, or what a better way might be to structure the code.






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


Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
Thanks for the suggestions so far. I've taken the advice to keep
things simple so currently I'm just creating one instance of the
commandHandler and assigning it a name with command = commandHandler
(). This makes it easy to call it from any of the other handlers, and
I think this will work for what I want the game to do.
--
http://mail.python.org/mailman/listinfo/python-list


Re: call function of class instance with no assigned name?

2009-05-06 Thread George Oliver
On May 6, 3:07 pm, Carl Banks  wrote:

> I'm going to guess that you want the keyboardHandler to call method of
> commandHandler.  There's no reason for commandHandler to be a handler
> at all then: keyboardHandler is already handling it.


Thanks Carl, you've got it right and your following example is what I
ended up using, it's good to know it's a workable solution.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python in a group

2008-06-22 Thread George Oliver
On Jun 22, 3:43 am, "Jonathan Roberts" <[EMAIL PROTECTED]>
wrote:
> Hi all,
>
> I'm looking to learn Python (as my first programming language) and I'm
> pretty sure I'd be more successful doing this with a group of other
> people.

hi Jon, I'm in the same situation as you and think a co-op method of
learning could be effective and fun. I found the Tutor list that David
mentioned a little while ago but also have been looking for a group
(without success so far). So count me in!


best, George

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


2D online multiplayer framework?

2008-06-28 Thread George Oliver
I'm looking for a framework to support a 2D online real-time
multiplayer game (rugby league football with a lo-fi pixel look). The
GameProgramming page at the Python wiki had some suggestions but so
far nothing looks that promising, does anyone have some
recommendations?

It would be ideal to play this through a web browser but I don't know
if that's practical.

This aspect of programming is pretty new to me so I'm not sure if I
should start with something general like Twisted or if there's a
different path I should take.


thanks, George
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2D online multiplayer framework?

2008-06-28 Thread George Oliver
On Jun 28, 9:04 am, Gary Herron <[EMAIL PROTECTED]> wrote:
>
> Pyglet is my favorite:  http://www.pyglet.org/
>
> Twisted might be fine for the "online multiplayer" parts, but really if
> you want a 2D/3D real-time game, start with a game framework.
>
> Gary Herron

Thanks Cédric and Gary for the suggestions, I'm familiar with all of
those. So a good workflow for a graphical online game is to make the
game first and just plan for the incoming connections without knowing
how they will be done exactly? My only experience with networked games
is muds, where usually you do the opposite -- sockets first.

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


sending input to an embedded application

2008-07-12 Thread George Oliver
hi, I'm a novice programmer trying to better define a hobby project
I'm thinking of.

What I would like to do is take a program and embed it or put it
within a Python-run GUI, using the GUI just to capture and send input
to the application, and display the ouput.

Specifically I want to use a Python module such as wxPython, pygame or
pyglet to build the UI, capture key presses, and then send a string to
the program, an interactive fiction interpreter; the reason for this
is that the interpreter on its own doesn't have the capability to
recognize certain key presses on the keyboard. I thought that writing
a middle layer rather than a brand new interpreter would be easier for
someone of my skill level.

The interpreter would send its output to the Python GUI. The GUI then
would be as light/translucent as possible, just accepting input,
sending it to the interpreter, and displaying the output as if you
were just running the interpreter by itself.

As I don't really know the issues involved, I'm hoping someone can
point me in the right direction. Do people 'frame' programs with
something like wxPython or pygame and use the frame to capture and
pass along input, and receive and display the output?


thanks, George
--
http://mail.python.org/mailman/listinfo/python-list


looking for Python live code reloading IDEs

2010-01-22 Thread George Oliver
hi, I'm wondering if there are any Python programming environments
that enable live code reloading, for example something like the Scheme-
based impromptu (but also meant for any kind of Python program, not
just audio/visual generation).

Currently I do this directly in my editor (for game development), but
I'm curious if there are other options.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newsgroup for beginners

2009-11-16 Thread George Oliver
On Nov 16, 8:35 am, Terry Reedy  wrote:
> mrholtsr wrote:
> > Is there a Python newsgroup for those who are strictly beginners at
> > programming and python?
>
> gmane.comp.python.tutor, which I believe mirrors the tutor-list

There also is a beginner's forum at python-forum.org:

http://www.python-forum.org/pythonforum/viewforum.php?f=3
-- 
http://mail.python.org/mailman/listinfo/python-list


string.Template question

2010-04-05 Thread Wells Oliver
Can you use dicts with string.Template?

e.g. a structure like:

game = {
'home': {'team': row['home_team_full'], 'score': 
row['home_score'],
'record': '0-0', 'pitcher': {
'id': home_pitcher.attrib['id'], 'name':
home_pitcher.attrib['last_name'], 'wins': home_pitcher.attrib['wins'],
'losses': home_pitcher.attrib['losses']
}, 'win': home_win}
}

Then, in the template, 'game' is passed, but I want to access like
$home.pitcher.id

This doesn't seem to work, though. Is it possible? Or must everything
in the dict passed to string.Template be one-level deep string
variables?
-- 
http://mail.python.org/mailman/listinfo/python-list


requirements in writing an email/rss/usenet client?

2010-08-08 Thread George Oliver
hi,

I'd like to know what to consider when writing an email/rss/usenet
client. Apologies for such a broad question, but I've never attempted
a project of this scope and I'm currently feeling out the
requirements.

My target is something like a gui-based mutt (I use a Windows OS btw),
with influences from programs like Alpine (http://www.washington.edu/
alpine/) and Sup (http://sup.rubyforge.org/).

I currently use Thunderbird + Muttator, which is a nice setup; but, it
has some clunky parts, and I thought it might be simpler in the end to
start fresh than try to engage with what seems to be the massive-ness
of Thunderbird (of course, I may be disabused of this notion at some
point ;) ).


So far I've looked at the email and related modules in the standard
lib, found some related links from the list [1], and read a little
about the relevant protocols involved.

I'd appreciate hearing about any other examples, references, or
experiences of people who've written similar programs or related
libraries.


thanks, George


[1] Including references to:

* http://sourceforge.net/projects/usablemail/
* http://proquest.safaribooksonline.com/0596000855/python2-CHP-11-SECT-4
* http://wiki.laptop.org/go/Email
* the pyne client
* http://chandler.osafoundation.org/



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


A question on scope...

2009-06-18 Thread Wells Oliver
In writing out python classes, it seems the 'self' is optional, meaning that
inside a class method, "self.foo = bar" has the same effect as "foo = bar".
Is this right? If so, it seems a little odd- what's the rationale?

Or am I mistaken?

-- 
Wells Oliver
we...@submute.net
-- 
http://mail.python.org/mailman/listinfo/python-list


n00b confusion re: local variable referenced before assignment error

2009-06-19 Thread Wells Oliver
Writing a class which essentially spiders a site and saves the files
locally. On a URLError exception, it sleeps for a second and tries again (on
404 it just moves on). The relevant bit of code, including the offending
method:

class Handler(threading.Thread):
def __init__(self, url):
threading.Thread.__init__(self)
self.url = url

def save(self, uri, location):
try:
handler = urllib2.urlopen(uri)
except urllib2.HTTPError, e:
if e.code == 404:
return
else:
print "retrying %s (HTTPError)" % uri
time.sleep(1)
self.save(uri, location)
except urllib2.URLError, e:
print "retrying %s" % uri
time.sleep(1)
self.save(uri, location)

if not os.path.exists(os.path.dirname(location)):
os.makedirs(os.path.dirname(location))

file = open(location, "w")
file.write(handler.read())
file.close()

...

But what I am seeing is that after a retry (on catching a URLError
exception), I see bunches of "UnboundLocalError: local variable 'handler'
referenced before assignment" errors on line 38, which is the
"file.write(handler.read())" line..

What gives?

-- 
Wells Oliver
we...@submute.net
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQLdb and ordering of column names in list returned by keys() w/ a DictCursor

2009-07-02 Thread Wells Oliver
Is there some kind of mysterious logic to how the the columns are ordered
when executing the following:

sql = "SELECT player_id, SUM(K) AS K, SUM(IP) AS IP, SUM(ER) AS ER, SUM(HR)
AS HR, SUM(H) AS H, SUM(BB) AS BB, Teams.league FROM Pitching INNER JOIN
Teams ON Pitching.team = Teams.team_id WHERE Date BETWEEN '%s' AND '%s'
GROUP BY player_id" % (start, date)
cursor.execute(sql)

for row in cursor.fetchall():
print row.keys()

What I get is:

['league', 'BB', 'HR', 'IP', 'K', 'H', 'player_id', 'ER']

Neither alphabetical nor the order in which they were specified in the query
nor... any seeming order I can suss out. Any ideas? Thanks!

(cursor being a MySQLdb.cursors.DictCursor object.)

-- 
Wells Oliver
we...@submute.net
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >