RE: TKinter in Python - advanced notions

2023-06-23 Thread Andreas Heckel via Python-list
Hi,

Apologies for potentially mis-using this thread. But I have been struggling 
recently making exactly this leap from simple GUI examples to a more elaborate 
MVVM concept. Mainly I have been struggling finding nice example python code 
bases, that allow some understanding to the beginner, which I certainly still 
am, but also show enough complexity to see the concept in action.
Any hints / links to github or similar highly welcome. If the list is not the 
appropriate place, I am happy if you email me directly.

Cheers,
Andreas

> -Original Message-
> From: Python-list 
> On Behalf Of Diego Souza via Python-list
> Sent: Friday, June 23, 2023 4:14 AM
> To: aapost 
> Cc: python-list
> Subject: Re: TKinter in Python - advanced notions
> 
> Have you considered improving the architecture itself, not your GUI library
> skills?
> 
> I recommend you look at the Model View ViewModel (MVVM) concept and
> implement something similar (this is largely used in the Android framework
> nowadays). This would separate your program logic from the rendering and
> visualization. It would also make your program more reactive, decoupled,
> and easier to maintain. When you mentioned threads I immediately thought of
> this because it is much easier to implement parallel jobs and present
> results back in the GUI, as everything becomes reactive. This is overkill
> for a small project such as the code you showed, but I recommend it for
> larger projects.
> 
> 
> 
> 
> 
> On Wed, Jun 21, 2023 at 7:20 PM aapost via Python-list <
> python-list@python.org> wrote:
> 
> > On 6/21/23 09:47, Dan Kolis wrote:
> > > I've write a huge biotech program ( an IDE for synthetic biology ), and
> > am slowly outgrowing TKINTER.
> > >
> > > Has anybody out there merged a little bit of TCL direct calls from
> > Python 3.X to get more freedom then TKINTER for just some Windows ?
> >
> > > I wish it looked better, but its 'ok'. I believe X11 IO is considerably
> > superior for serious work the HTML.  I mean 'serious' work. with lots of
> > multi media windows. I am not talking about fb "Oh ! There is a window it
> > opened inthe corner !"... trivial functionality.
> >
> >
> > I don't know if it would help, but you can extend/add tcl/tk packages
> >
> > I don't remember the full instructions right off, but quickly reverse
> > engineering my old stuff I think you just need to drop them in
> > /usr/share/tcltk/ or equivalent.
> >
> > (I needed to do that to replace the terrible looking default file dialog
> > for unix/linux with fsdialog.)
> >
> > then running something like the following from your Tk object
> >
> > self.eval('package require fsdialog')
> >
> > (reverse engineering the python tkinter source you can likely find other
> > ways of doing more tcl direct stuff)
> >
> > I have not researched if there are some better, more featured
> > (non-buggy) Text widgets implemented in tcl that can be dropped in, (I
> > know several of the tcl drop in widgets I tried were lacking in
> > refinement).
> >
> >  From what I can tell, once upon a time there were better, more
> > interesting projects and tutorials on extending tkinter, such as WCK
> > (tkinter3000), but the only remnants of those remain publicly available
> > are outdated unmaintained archives.
> >
> > You might also consider looking at the Grail browser source for research
> > purposes, as it does some interesting things with some of the widgets,
> > (parsing html and such), even though it is 20 years old now (and written
> > in python 1).
> > The update attempts from 10+ years ago have disappeared. (it's license
> > is considered questionable from what I understand, so not sure if that
> > is an aspect of it, the other being one of it's main features, python
> > applets, is unsafe and was not easily fixable)
> >
> > You might already be beyond some of these things though.
> >
> > I know what you mean as far is feeling like the little bit extra you
> > need pushes beyond what tkinter can do / makes you feel like you have
> > outgrown the module.
> >
> > (I had to take a break from one of my projects and send it to
> > development hell until my UI knowledge/skills improve after I found
> > myself considering using xml schema appinfo annotations to store json
> > formatted widget specific information, lol.)
> >
> > I have felt that sense of lack with most of the UI modules I have tried
> > though.
> >
> > I don't know of a clear better python-onl

Re: built-in pow() vs. math.pow()

2023-04-03 Thread Andreas Eisele
Andreas Eisele schrieb am Donnerstag, 30. März 2023 um 11:16:02 UTC+2:
> I sometimes make use of the fact that the built-in pow() function has an 
> optional third argument for modulo calculation, which is handy when dealing 
> with tasks from number theory, very large numbers, problems from Project 
> Euler, etc. I was unpleasantly surprised that math.pow() does not have this 
> feature, hence "from math import *" overwrites the built-in pow() function 
> with a function that lacks functionality. I am wondering for the rationale of 
> this. Does math.pow() do anything that the built-in version can not do, and 
> if not, why is it even there? 
> Thanks in advance for any enlightening comment on this. 
> Best regards, Andreas

Thanks a lot to all of you for the insightful replies! 
I now understand why math.pow() behaves the way it does and whoever tells me I 
should have read the doc of the math module before using it is 100% on point. 
BTW, there is another difference: built-in pow() deals with complex arguments, 
while functions in math won't accept them at all.
I also agree with the warning that importing * from any module is generally a 
bad idea, and I normally would not do it.  But here I had written a little tool 
that evaluates an expression given on the command line, and in this case having 
math functions available without further ado is very convenient, so it seemed 
appropriate to make an exeption to this rule.
I ended up assigning the built-in pow function to a different name before 
importing the math module, which is a good way to keep both variants accessible.
Best regards, and thanks again, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


built-in pow() vs. math.pow()

2023-03-30 Thread Andreas Eisele
I sometimes make use of the fact that the built-in pow() function has an 
optional third argument for modulo calculation, which is handy when dealing 
with tasks from number theory, very large numbers, problems from Project Euler, 
etc. I was unpleasantly surprised that math.pow() does not have this feature, 
hence "from math import *" overwrites the built-in pow() function with a 
function that lacks functionality. I am wondering for the rationale of this. 
Does math.pow() do anything that the built-in version can not do, and if not, 
why is it even there?
Thanks in advance for any enlightening comment on this.
Best regards, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-17 Thread Andreas Eder
On Mi 12 Okt 2022 at 05:00, Paulo da Silva 
 wrote:

> The simple question: How do I find the full path of a shell command
> (linux), i.e. how do I obtain the corresponding of, for example,
> "type rm" in command line?
>
> The reason:
> I have python program that launches a detached rm. It works pretty well
> until it is invoked by cron! I suspect that for cron we need to specify
> the full path.
> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
> What about other commands?

Why not just use os.unlink ?

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


Re: Performance issue with CPython 3.10 + Cython

2022-10-07 Thread Andreas Ames
Answering to myself, just for the records:

1. The culprit was me. As lazy as I am, I have used f-strings all over the
place in calls to `logging.logger.debug()` and friends, evaluating all
arguments regardless of whether the logger was enabled or not.  Replacing
these f-strings by regular printf-like format strings solved the issue.
Now the application bowls happily along, consistently below 0.02 seconds
per second application time.
2. Valgrind + callgrind is an awesome toolchain to spot performance issues,
even on VMs.


Am Di., 4. Okt. 2022 um 11:05 Uhr schrieb Andreas Ames <
andreas.0815.qwe...@gmail.com>:

> Hi all,
>
> I am wrapping an embedded application (, which does not use any dynamic
> memory management,) using Cython to call it from CPython.  The wrapped
> application uses a cyclic executive, i.e. everything is done in the
> input-logic-output design, typical for some real-time related domains.
> Consequentially, every application cycle executes more or less the very
> same code.  As I am still in a prototyping stadium, the wrapped process is
> completely CPU-bound, i.e. except of some logging output there is no I/O
> whatsoever.
>
> During one second of "application time", I am doing exactly 120 calls into
> the application through three Cython-wrapped API functions.  The
> application uses some platform-dependent APIs, which I have also wrapped
> with Cython, so that there are numerous callbacks into the Python realm per
> call into the application. What I am observing now, is that the performance
> per "application second" decreases (remember: executing code that does the
> same thing on every cycle) and extending the number of loop iterations does
> not seem to cause any bound to this decrease.  In the log ouput below, you
> can see the GC counts, which look innocent to me.  The "real time" is
> measured using "time.time()". The "top" utility does not suggest any memory
> leak either.  I am developing on WSL2, but I have checked that this
> performance effect also happens on physical machines.  Right now, I am
> staring at "kcachegrind", but I have no idea, how to determine time series
> for the performance of functions (I am not looking for those functions,
> which need the most time, but for those, which consume more and more
> execution time).
>
> One more thing to look for could be memory fragmentation, but before that
> I would like to ask the experts here for their ideas and experiences and/or
> for tools, which could help to find the culprit.
>
> 2022-10-04 10:40:50|INFO|__main__   |Execution loop 0 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.06862711906433105 seconds real time.
>> 2022-10-04 10:40:51|INFO|__main__   |Execution loop 100 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.08224177360534668 seconds real time.
>> 2022-10-04 10:40:52|INFO|__main__   |Execution loop 200 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.08225250244140625 seconds real time.
>> 2022-10-04 10:40:53|INFO|__main__   |Execution loop 300 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.10176873207092285 seconds real time.
>> 2022-10-04 10:40:54|INFO|__main__   |Execution loop 400 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.10900592803955078 seconds real time.
>> 2022-10-04 10:40:55|INFO|__main__   |Execution loop 500 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.12233948707580566 seconds real time.
>> 2022-10-04 10:40:56|INFO|__main__   |Execution loop 600 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.14058256149291992 seconds real time.
>> 2022-10-04 10:40:58|INFO|__main__   |Execution loop 700 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.14777183532714844 seconds real time.
>> 2022-10-04 10:40:59|INFO|__main__   |Execution loop 800 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.15729451179504395 seconds real time.
>> 2022-10-04 10:41:01|INFO|__main__   |Execution loop 900 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.17365813255310059 seconds real time.
>> 2022-10-04 10:41:03|INFO|__main__   |Execution loop 1000 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.17772984504699707 seconds real time.
>> 2022-10-04 10:41:05|INFO|__main__   |Exec

Performance issue with CPython 3.10 + Cython

2022-10-04 Thread Andreas Ames
-10-04 10:41:16|INFO|__main__   |Execution loop 1600 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.2541334629058838 seconds real time.
> 2022-10-04 10:41:19|INFO|__main__   |Execution loop 1700 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.26812195777893066 seconds real time.
> 2022-10-04 10:41:21|INFO|__main__   |Execution loop 1800 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.28777456283569336 seconds real time.
> 2022-10-04 10:41:24|INFO|__main__   |Execution loop 1900 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3005337715148926 seconds real time.
> 2022-10-04 10:41:28|INFO|__main__   |Execution loop 2000 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.30992960929870605 seconds real time.
> 2022-10-04 10:41:31|INFO|__main__   |Execution loop 2100 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.32058119773864746 seconds real time.
> 2022-10-04 10:41:34|INFO|__main__   |Execution loop 2200 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.33020949363708496 seconds real time.
> 2022-10-04 10:41:37|INFO|__main__   |Execution loop 2300 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.34426307678222656 seconds real time.
> 2022-10-04 10:41:41|INFO|__main__   |Execution loop 2400 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3585126338965 seconds real time.
> 2022-10-04 10:41:45|INFO|__main__   |Execution loop 2500 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3664553165435791 seconds real time.
> 2022-10-04 10:41:48|INFO|__main__   |Execution loop 2600 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3767662048339844 seconds real time.
> 2022-10-04 10:41:52|INFO|__main__   |Execution loop 2700 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.39760732650756836 seconds real time.
> 2022-10-04 10:41:56|INFO|__main__   |Execution loop 2800 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.42221736907958984 seconds real time.
> 2022-10-04 10:42:01|INFO|__main__   |Execution loop 2900 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.4237234592437744 seconds real time.


Thanks in advance,

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


Re: Parallel(?) programming with python

2022-08-15 Thread Andreas Croci
I would like to thank everybody who answered my question. The insight 
was very informative. This seems to be one of the few newsgroups still 
alive and kicking, with a lot of knowledgeable people taking the time to 
help others. I like how quick and easy it is to post questions and 
receive answers here as compared to web-based forums (although there are 
some disadvantages too).


I'm implementing some of the ideas received here and I will surely have 
other questions as I go. But the project will take a long time because 
I'm doing this as a hobby during my vacation, that are unfortunately 
about to end.


Thanks again, Community.

On 08.08.22 12:47, Andreas Croci wrote:
tI would like to write a program, that reads from the network a fixed 
amount of bytes and appends them to a list. This should happen once a 
second.


Another part of the program should take the list, as it has been filled 
so far, every 6 hours or so, and do some computations on the data (a FFT).


Every so often (say once a week) the list should be saved to a file, 
shorthened in the front by so many items, and filled further with the 
data coming fom the network. After the first saving of the whole list, 
only the new part (the data that have come since the last saving) should 
be appended to the file. A timestamp is in the data, so it's easy to say 
what is new and what was already there.


I'm not sure how to do this properly: can I write a part of a program 
that keeps doing its job (appending data to the list once every second) 
while another part computes something on the data of the same list, 
ignoring the new data being written?


Basically the question boils down to wether it is possible to have parts 
of a program (could be functions) that keep doing their job while other 
parts do something else on the same data, and what is the best way to do 
this.


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


Re: Parallel(?) programming with python

2022-08-08 Thread Andreas Croci

Thank you for your reply.

On 08.08.22 14:55, Julio Di Egidio wrote:


Concurrent programming is quite difficult, plus you better think
in terms of queues than shared data... 


Do you mean queues in the sense of deque (the data structure)? I ask 
because I can see the advantage there when I try to pop data from the 
front of it, but I don't see the sense of the following statement ("than 
shared data"). I mean, I called my structure a list, but it may well be 
a queue instead. That wouldn't prevent it from being shared in the idea 
I described: one function would still append data to it while the other 
is reading what is there up to a certain point and calculate the FFT of it.


 But, an easier and often

better option for concurrent data access is use a (relational)
database, then the appropriate transaction isolation levels
when reading and/or writing.



That would obviusly save some coding (but would introduce the need to 
code the interaction with the database), but I'm not sure it would speed 
up the thing. Would the RDBMS allow to read a table while something else 
is writing to it? I doubt it and I'm not sure it doesn't flush the cache 
before letting you read, which would include a normally slow disk access.


Andreas


Julio


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


Re: Parallel(?) programming with python

2022-08-08 Thread Andreas Croci

Thanks for your reply.

On 08.08.22 13:20, Stefan Ram wrote:


   Yes, but this is difficult. If you ask this question here,
   you might not be ready for this.


Indeed.



   I haven't learned it yet myself, but nevertheless tried to
   write a small example program quickly, which might still
   contain errors because of my lack of education.

import threading
import time

def write_to_list( list, lock, event ):
 for i in range( 10 ):
 lock.acquire()
 try:
 list.append( i )
 finally:
 lock.release()
 event.set()
 time.sleep( 3 )

def read_from_list( list, lock, event ):
 while True:
 event.wait()
 print( "Waking up." )
 event.clear()
 if len( list ):
 print( "List contains " + str( list[ 0 ]) + "." )
 lock.acquire()
 try:
 del list[ 0 ]
 finally:
 lock.release()
 else:
 print( "List is empty." )

list = []
lock = threading.Lock()
event = threading.Event()
threading.Thread( target=write_to_list, args=[ list, lock, event ]).start()
threading.Thread( target=read_from_list, args=[ list, lock, event ]).start()


If I understand some things correctly, a "lock" would be something that, 
as the name says, locks, meaning prevents parts of the program from 
executing on the locked resource until ohter parts have finished doing 
their things and have released the lock. If this is correct, it's not 
exactly what I wanted, because this way "parts of the program" would not 
"keep doing their things, while other parts do other things on the same 
data".


I'm in principle ok with locks, if it must be. What I fear is that the 
lock could last long and prevent the function that writes into the list 
from doing so every second. With an FFT on a list that contains a few 
bytes taken every second over one week time (604.800 samples), I believe 
it's very likely that the FFT function takes longer than a second to return.


Then I would have to import all the data I have missed since the lock 
was aquired, which is doable, but I would like to avoid it if possible.




   In basketball, first you must learn to dribble and pass,
   before you can begin to shoot.


Sure.



   With certain reservations, texts that can be considered
   to learn Python are:

"Object-Oriented Programming in Python Documentation" - a PDF file,
Introduction to Programming Using Python - Y Daniel Liang (2013),
How to Think Like a Computer Scientist - Peter Wentworth (2012-08-12),
The Coder's Apprentice - Pieter Spronck (2016-09-21), and
Python Programming - John Zelle (2009).



Thank you for the list. I an currently taking a Udemy course and at the 
same time reading the tutorials on python.org. I hope I will some day 
come to any of the books you suggest (I'm doing this only in my spare 
time and it will take forever).

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


Parallel(?) programming with python

2022-08-08 Thread Andreas Croci
tI would like to write a program, that reads from the network a fixed 
amount of bytes and appends them to a list. This should happen once a 
second.


Another part of the program should take the list, as it has been filled 
so far, every 6 hours or so, and do some computations on the data (a FFT).


Every so often (say once a week) the list should be saved to a file, 
shorthened in the front by so many items, and filled further with the 
data coming fom the network. After the first saving of the whole list, 
only the new part (the data that have come since the last saving) should 
be appended to the file. A timestamp is in the data, so it's easy to say 
what is new and what was already there.


I'm not sure how to do this properly: can I write a part of a program 
that keeps doing its job (appending data to the list once every second) 
while another part computes something on the data of the same list, 
ignoring the new data being written?


Basically the question boils down to wether it is possible to have parts 
of a program (could be functions) that keep doing their job while other 
parts do something else on the same data, and what is the best way to do 
this.

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


Immutable view classes - inherit from dict or from Mapping?

2021-04-12 Thread Andreas R Maier
Hi,
I have written some classes that represent immutable views on collections (see 
"immutable-views" package on Pypi).

Currently, these view classes inherit from the abstract collection classes such 
as Mapping, Sequence, Set. However, they implement the read-only methods of 
dict, list and set, which provides some more methods compared to the abstract 
collection classes. For example, class "dict" provides copy() or __reversed__() 
and the newer OR-operator methods all of which are not defined on the abstract 
class "Mapping".

Note that the view classes do not provide any of the modifying methods of 
"dict" and "list", because after all the views are supposed to be immutable.

My question is, should the dict view class inherit from Mapping or from dict, 
and likewise, should the list view class inherit from Sequence or from list?

Thanks
Andy

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


Installation Python 3.6.x on Windows using command line installer (without GUI)

2017-07-27 Thread Andreas Jung

I need to installed Python 3.6.x on Windows as part of an automated process 
without user-interaction. Recently Python releases provided MSI files for 
installation using the "msiexec" utility however there are no more MSI release 
files available for Python 3.6.X. Are there any alternatives?

-aj

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


Re: subprocess problem

2017-02-15 Thread Andreas Paeffgen

On 2017-02-11 02:23:12 +, Cameron Simpson said:


  def your_function(...):
with open('/path/to/your/logfile.txt', 'a') as logfp:
  print("PATH=".os.environ['PATH'], file=logfp)
  p=Popen(...)
  p.communicate(...)
  print("p.returncode=%r" % (p.returncode))

and any other interesting values that occur to you. This is really simple, and
doesn't require a terminal or using the logging module.

You can 'tail -f /path/to/your/logfile.txt' in another terminal to watch stuff
happen as you exercise the program.


Thanks for the great advice.
I found out, that the frozen app does not pass the normal path 
variable. All the tricks with passing the correct environment did not 
work. I just hardcoded the existing standard path. After that it worked.


I think it is a problem with frozen apps in general. Cx_Freeze has 
other problems than Pyinstaller. But all need some workarounds for the 
problems.




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


Re: subprocess problem

2017-02-10 Thread Andreas Paeffgen

Thanks for all the great advice.
I tested all the possibilities. So far no luck. If i start the app from 
a terminal, the solutions work. But not, if i start the app-bundle 
(There is no connection to a terminal)


1. Copied the path to p.subprocess
2. Used the def wich: python function
3. Used shutil

When there is no Terminal, there is no error message / status code message.


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


Re: subprocess problem

2017-02-09 Thread Andreas Paeffgen
I guess which does not return an error code. If it does not find 
anything, the return is just blank. If it finds something, the path is 
returned.


So the change of code did not help, because there is just no error message.
Could there be a $path problem in the subprocess started inside the binary?


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


Re: subprocess problem

2017-02-09 Thread Andreas Paeffgen
Maybe i could use another trick to circumvent the problems in the 
frozen app? The frozen apps can be downloaded here: 
https://sourceforge.net/projects/panconvert/files/Newest/


@Cameron:

1. I use PyQT5 for a creating a gui app. To run the app on other 
systems, where no QT5 and PyQT5 is installed, a bundle is created with 
all relevant libraries, so it will start independently. This app 
bundle, is called a frozen app. Not only the source code, but all it 
dependencies are distributed including python3 itself.


2. In the test-environment pandoc is installed in /usr/local/bin/pandoc 
(Mac) or /bin/pandoc (Linux). Which returns the path correctly, at the 
terminal (shell), in Python and in the Gui-App Panconvert.


3. I am aware of the limitations of which. There is a fallback to 
manually insert the path. So the app will function anyway.  And i want 
to avoid to search the whole filesystem. This takes minutes on my test 
machines, so this is no option.


4. I suppose that something is different from executing the code in the 
frozen state. The app e.g. on Mac is not started from a python shell or 
a comand shell. But even on linux, when started from a shell it does 
not work.


5. I will try the hint with dev.null and the p.check_returncode()



@Wolfgang

1. The function should be executed only, if the path is unknown. If the 
user enters the path manually in the settings and pandoc exists, the 
function should not be executed to save computation time.


2. Only if the manually entered path is not correct or empty the 
function should be executed,  hence 'if not os.path.isfile(path_pandoc)'


3. The function fills in the path automatically if which returns a 
value. This works in the source code



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


subprocess problem

2017-02-08 Thread Andreas Paeffgen
The Problem with the subprocess code is: Using the sourcecode 
functioning as normal.

The frozen app with cx_freeze on every platform just returns an empty result

Here is the code in short:
def get_path_pandoc():




   settings = QSettings('Pandoc', 'PanConvert')

   path_pandoc = settings.value('path_pandoc','')




   if not os.path.isfile(path_pandoc):




   if platform.system() == 'Darwin' or os.name == 'posix':

   args = ['which', 'pandoc']

   p = subprocess.Popen(

   args,

   stdin=subprocess.PIPE,

   stdout=subprocess.PIPE)




   path_pandoc = 
str.rstrip(p.communicate(path_pandoc.encode('utf-8'))[0].decode('utf-8')) 




The whole problematic code can be checked on 
http://github.com/apaeffgen/panconvert

in source/converters/interface_pandoc.py

I debugged it with some QMessage-Boxes. I just know, that the returnd 
result is empty.

I tried some stderr on this code also. But also the error message is empty.

Any hints what could be changed in the code, so it also works in the 
frozen app?


At the moment i use python3.4 to 3.5 depending on the platform (Mac, 
Win, Linux)


P.S. Tried also some code with invoking the bash and afterwords the 
which pandoc code. To know avail also




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


Re: Call for Assistance

2016-08-11 Thread Andreas Röhler



On 12.08.2016 06:48, Lawrence D’Oliveiro wrote:

On Wednesday, August 10, 2016 at 3:42:39 AM UTC+12, Reto Brunner wrote:

What on earth isn't "free" enough about

You are free to:
Share — copy and redistribute the material in any medium or format

No you are not. A court has ruled 

 quite clearly that “non-commercial” means PERSONAL USE ONLY, no redistribution or 
republication.


The court ruled at the special case. The institution in question is paid 
by all germans due to a kind of fea imposed - "Rundfunkbeitrag". 
Everyone owning or renting an object in Germany has to pay to them - 
without regard if they uses that media or not. If you have to pay to 
someone, you would not consider that relation non-commercial.

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 11:42, Lawrence D’Oliveiro wrote:

On Thursday, June 30, 2016 at 9:31:29 PM UTC+12, Andreas Röhler wrote:


Science is not about believing, but about models.

The nice thing about science is, it works even if you don’t believe in it.



Thats it!
--
https://mail.python.org/mailman/listinfo/python-list


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 10:24, Steven D'Aprano wrote:

On Thursday 30 June 2016 12:13, Rustom Mody wrote:


The irrational and emotional psychological forces that inspire mathematicians
can make interesting reading, but they have no relevance in deciding who is
write or wrong.


Hmm, so math is not inspired by solving real world problems, for example 
in physics or big-data?




  No numbers are real.


Numbers express relations, which are represented as symbols. So far they 
are real, as math exists, the human mind exists.


We don't have any natural numbers, assume Kronecker made a joke. 
"Natural numbers" is the most misleading term in the field maybe.


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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 10:24, Steven D'Aprano wrote:

On Thursday 30 June 2016 12:13, Rustom Mody wrote:

[ ... ]
Besides, the whole point of science is to develop objective, rational reasons
to believe things.


Science is not about believing, but about models.
Believing is important to make the career of a scientist maybe, it's for 
people outside.

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 03:33, Lawrence D’Oliveiro wrote:


So you see, like it or not, we are drawn to the conclusion that there *was* 
indeed something before our particular Big Bang.


That's linear like the Big Bang theorie. What about assuming something 
beyond our notion of time and space, unknown still?

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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 14:08, Antoon Pardon wrote:

Op 23-06-16 om 13:45 schreef Chris Angelico:

On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon
 wrote:

I don't care. In modern mathematics, zero is usaly defined as the
empty set. The empty set contains nothing, but it isn't nothing
itself. Otherwise the empty set would be the same as the set
containing the empty set, since they both would contain the same,
being nothing.

Zero is *the cardinality of* the empty set. The set containing the
empty set has a cardinality of 1.

In modern set theory where the integers are defined as specific kind
of sets, zero *is* the empty set.



Modes are like waves. If one wave arrives being "modern", lets watch out 
for the next.


There not just one set-theory, math is neither revealed nor received on 
some mount - even if the notion of truth has some theological 
connotations ;)

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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 11:46, Marko Rauhamaa wrote:


Ridiculous? It was this line of thinking that led Paul Dirac to predict
the existence of antimatter.


Marko


Yeah. Maybe we could construct examples already using antagonistic 
charges of electrons?

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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 11:17, Steven D'Aprano wrote:

[ ... ]
We can derive arithmetic from set theory.


IMO not, resp. not really. But that would make a another item, pretty 
off-topic from Python.


Should you know a place where to continue, would like to follow up.

Thanks BTW.


  Zero is very special: it is defined
as the empty set:

0: {}

The successor of zero (namely, one) is the set of all empty sets:

1: {{}}

Two is the set of zero and one:

2 = {{}, {{}}}

and so forth.





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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 10:17, Antoon Pardon wrote:

Op 23-06-16 om 09:05 schreef Steven D'Aprano:

On Thursday 23 June 2016 16:34, Andreas Röhler wrote:


Indeed, why should the result of 4 - 4 have a different truth-value than
4 - 3 ?

Because 4-4 is zero, which is "nothing", while 4-3 is one, which is
"something".

No zero is not nothing. If zere is nothing and an empty list is nothing,
I would expect zero to be an empty list or that they could be used 
interchangebly.




There is a fundamental diff between zero and emptiness.

Zero is just a relation in the realm of integers. It tells being in the 
midst between positiv and negativ infinity.
Number one tells being one unit towards positiv infinity in relation to 
negativ infinity. And so on.


Whilst emptiness tells about non-existence.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 09:05, Steven D'Aprano wrote:

On Thursday 23 June 2016 16:34, Andreas Röhler wrote:


Indeed, why should the result of 4 - 4 have a different truth-value than
4 - 3 ?

Because 4-4 is zero, which is "nothing",


Hmm,  water freezes at zero degree celsius, because there is no temperature?


  while 4-3 is one, which is
"something".

You might as well ask why False and True have different truth values.
Ironically, in a manner of speaking you *did* ask that, since 4-3 == True and
4-4 == False.




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


Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Andreas Röhler



On 23.06.2016 06:47, Lawrence D’Oliveiro wrote:

On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote:

On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote:

* boolean operators don’t have to operate on boolean values. The
   language spec
   
   says:

 “...the following values are interpreted as false: False, None, numeric
 zero of all types, and empty strings and containers (including strings,
 tuples, lists, dictionaries, sets and frozensets). All other values are
 interpreted as true.”

I feel that’s a needlessly complicated rule. It would have been simpler if
boolean operators (and conditional expressions like in if-statements and
while-statements) only allowed values of boolean types. But that’s one of
the few warts in the design of Python...

Wart??  I *strongly* disagree.  I find it one of the strengths of Python,
it enhances Python's expressiveness.

Tightening it up would rule out a whole class of common errors, from misunderstanding (or 
forgetting) the rule about what exactly gets interpreted as true and what as false 
 
.


Indeed, why should the result of 4 - 4 have a different truth-value than 
4 - 3 ?
This implementation seems to be a legacy from languages without boolean 
types.

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


Re: Distinction between “class” and “type”

2016-05-14 Thread Andreas Röhler



I suspect that one could produce a class that is not a type,


Say: has not a complete type definition. Think of type for example with 
the distinction of strings and numbers.


Types start from low level units. A class definition must know about 
strings and numbers, it inherits this knowledge from the syntax of 
language. Even an empty class must be constructed.


Types may be composed resp derived from other types. Any class finely 
will constitute a type composed by its body.


In case an definition may used for example equally for addition or 
string-concatenation, ambiguity constitutes a composed resp. derived 
type by themselves.


In general terms: the type tells the structure of arguments it receives 
alongside with the way, it deals with them.




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


Python 3.5.0b2 - permission error after pip upgrade

2015-06-11 Thread Andreas Balogh
I've installed a fresh copy of Python 3.5.0b2 and - as recommended - upgraded 
pip. I don't
understand the reason for the permission errors as I am owner and have full 
control for
the temporary directory created.

What can I do to fix this?


C:\Apps\Python35>pip install --upgrade pip
You are using pip version 7.0.1, however version 7.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pip
  Downloading pip-7.0.3-py2.py3-none-any.whl (1.1MB)
100% || 1.1MB 422kB/s
Installing collected packages: pip
  Found existing installation: pip 7.0.1
Uninstalling pip-7.0.1:
  Successfully uninstalled pip-7.0.1
Exception:
Traceback (most recent call last):
  File "C:\Apps\Python35\lib\shutil.py", line 377, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied:
'C:\\Users\\Andreas\\AppData\\Local\\Temp\\pip-xf9kwi7g-uninstall\\apps\\python35\\scripts\\pip.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Apps\Python35\lib\site-packages\pip\basecommand.py", line 223, in 
main
status = self.run(options, args)
  File "C:\Apps\Python35\lib\site-packages\pip\commands\install.py", line 297, 
in run
root=options.root_path,
  File "C:\Apps\Python35\lib\site-packages\pip\req\req_set.py", line 633, in 
install
requirement.commit_uninstall()
  File "C:\Apps\Python35\lib\site-packages\pip\req\req_install.py", line 734, in
commit_uninstall
self.uninstalled.commit()
  File "C:\Apps\Python35\lib\site-packages\pip\req\req_uninstall.py", line 153, 
in commit
rmtree(self.save_dir)
  File "C:\Apps\Python35\lib\site-packages\pip\_vendor\retrying.py", line 49, 
in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "C:\Apps\Python35\lib\site-packages\pip\_vendor\retrying.py", line 212, 
in call
raise attempt.get()
  File "C:\Apps\Python35\lib\site-packages\pip\_vendor\retrying.py", line 247, 
in get
six.reraise(self.value[0], self.value[1], self.value[2])
  File "C:\Apps\Python35\lib\site-packages\pip\_vendor\six.py", line 659, in 
reraise
raise value
  File "C:\Apps\Python35\lib\site-packages\pip\_vendor\retrying.py", line 200, 
in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "C:\Apps\Python35\lib\site-packages\pip\utils\__init__.py", line 89, in 
rmtree
onerror=rmtree_errorhandler)
  File "C:\Apps\Python35\lib\shutil.py", line 484, in rmtree
return _rmtree_unsafe(path, onerror)
  File "C:\Apps\Python35\lib\shutil.py", line 374, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
  File "C:\Apps\Python35\lib\shutil.py", line 374, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
  File "C:\Apps\Python35\lib\shutil.py", line 374, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
  File "C:\Apps\Python35\lib\shutil.py", line 379, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Apps\Python35\lib\site-packages\pip\utils\__init__.py", line 101, in
rmtree_errorhandler
func(path)
PermissionError: [WinError 5] Access is denied:
'C:\\Users\\Andreas\\AppData\\Local\\Temp\\pip-xf9kwi7g-uninstall\\apps\\python35\\scripts\\pip.exe'


-- 
baloand (at) gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Probem with fbconsole

2015-01-04 Thread Ole Andreas Gløersen
I want to enter text msg and upload picture (so all friends can see and some 
private pictures) to my Facebook acount.

I'm working with fbconsole (it's important that it is text based command line) 
for setting up cron job on a Raspberry Pi.

My code:

import fbconsole

redirect_uri =  "https://local.fbconsole.com:8080/";
fbconsole.SITE_URL=redirect_uri

fbconsole.APP_ID = 'my_SW_ID'

fbconsole.AUTH_SCOPE = ['read_stream']
fbconsole.automatically_authenticate('my_FB_ID','my_FB_PWD','Security_code',fbconsole.SITE_URL,True)



My result:

pi@raspberrypi ~/facebook $ python f.py 
send: 'GET 
/dialog/oauth?scope=read_stream&state=DeletetDeletet&redirect_uri=https%3A%2F%2Flocal.fbconsole.com%3A8080%2F&client_id=Deletet
 HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: www.facebook.com\r\nConnection: 
close\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) 
Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Pragma: no-cache
header: Facebook-API-Version: v2.2
header: X-Frame-Options: DENY
header: Cache-Control: private, no-cache, no-store, must-revalidate
header: Expires: Sat, 01 Jan 2000 00:00:00 GMT
header: X-XSS-Protection: 0
header: X-Content-Type-Options: nosniff
header: Content-Type: text/html; charset=utf-8
header: X-FB-Debug: Deletet.Deletet
header: Date: Sun, 04 Jan 2015 16:51:31 GMT
header: Connection: close
Traceback (most recent call last):
  File "f.py", line 13, in 

fbconsole.automatically_authenticate('Deletet','Deletet','Deletet',fbconsole.SITE_URL,True)
  File "/usr/local/lib/python2.7/dist-packages/fbconsole.py", line 413, in 
automatically_authenticate
browser.select_form(nr=0)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 
524, in select_form
raise FormNotFoundError("no form matching "+description)
mechanize._mechanize.FormNotFoundError: no form matching nr 0
pi@raspberrypi ~/facebook $ 


Can anyone help me futher on?


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


Re: Emacs python-mode.el bug #1207470

2014-02-14 Thread Andreas Röhler

Am 14.02.2014 17:38, schrieb Frank Stutzman:

According to https://bugs.launchpad.net/python-mode/+bug/1207470 this bug
was fixed in version 6.1.2 of python-mode.el.  I am trying to run 6.1.3 and
am running into it.  I back dated to 6.1.2 and still see it there.  I am
running GNU Emacs 23.3.1.

Its possible that something I'm doing it causing it, but I have no idea
what.  I can start emacs with no init file, load python mode, hit enter
and I get the error.

Has anyone else experienced this?  I am sure that Andreas Roehler (the
maintainer of python-mode.el) fixed it, but am thinking that it somehow
didn't make it into the released code.

Frank



Re-opened the ticket mentioned. Please subscribe there, so you may get the 
bug-mail.

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


Re: How to check the date validity?

2013-12-23 Thread Andreas Perstinger
Jason Friedman  wrote:
>Would this not work?
>import re
>if re.search(r"\d{1,2}:\d{2}:\d{2}(.\d{1,3})?", "12:55:55.705"):
># It's a time

No, because this regexp also matches stuff like "99:99:99.999".
Checking for the number of digits is not enough, because not all
combinations of two digits are valid hours, minutes or seconds.

Bye, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Datetime string reformatting

2013-12-22 Thread Andreas Perstinger

On 22.12.2013 11:58, Igor Korot wrote:

My script receives a data from the csv file. In this csv file there is
a datetime field.
This datetime field is formatted as follows: %m/%d/%Y
%H:%M:%S.{milliseconds}. I'm reading this field into the string with
this format.

The trouble comes from the fact that I need to insert this value into
mySQL. Doing it directly gives me an error: "Incorrect formatting".
After a bit of googling and trial I found out that mySQL is looking
for the format of '%Y/%m/%d %H:%M:%S.{milliseconds}.

There is a mySQL function which transfers the data into the proper
format: STR_TO_DATE(), but I can't obviously call it since it is not
known to Python.


You don't want to call "STR_TO_DATE()" from Python but use it inside the 
SQL statement.


So instead of doing the conversion in Python as Mark suggested, you 
could do something like


sql_stmt = """INSERT ...
  VALUES (..., STR_TO_DATE(%s, "%m/%d/%Y %H:%M:%S.{%f}"),
  ...)"""
cursor.execute(sql_stmt, (..., mydate_from_csv, ...))

(BTW: Do you mean microseconds instead of milliseconds? And are the 
"milliseconds" really inside curly braces?)


Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: PDFMiner install question

2013-12-20 Thread Andreas Perstinger
Jason Mellone  wrote:
>I get the following error:
>PS C:\USERS\Python27> .\python.exe .\MyTest.py
>Traceback (most recent call last):
>  File ".\MyTest.py", line 4, in 
>from pdfminer.pdfpage import PDFTextExtractionNotAllowed
>ImportError: cannot import name PDFTextExtractionNotAllowed
>
>
>If I run commenting out the import of "PDFTextExtractionNotAllowed" it
>runs without a problem. Quite odd.

According to the latest version on Github,
"PDFTextExtractionNotAllowed" was moved into the "PDFPage" class, but
the sample code in the docs was obviously not updated.

https://github.com/euske/pdfminer/blob/master/pdfminer/pdfpage.py

So just leave out that line and if you need that exception use
"PDFPage.PDFTextExtractionNotAllowed" instead of
"PDFTextExtractionNotAllowed".

Bye, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need Help with the BeautifulSoup problem, please

2013-12-16 Thread Andreas Perstinger

On 16.12.2013 07:41, seasp...@gmail.com wrote:

I need to replace all tag  with  after ■. But the result
frombelow is '■ D / '
Can you explain what I did wrong, please.

 s = '■A B C D / '
 soup = BeautifulSoup(s)
 for i in soup.find_all(text='■'):
 tag = soup.new_tag('span')
 tag['style'] = 'REPLACE'
 for ii in i.find_next_siblings():
 if ii.name=='font' or str(ii).lstrip('')[0:1]=='/':
 break
 else:
 if ii.name=='b':
 tag.string=ii.string
 print(ii.replace_with(tag))
 print(soup)



You are only creating one new tag but as I understand your problem you 
want to replace each b-element with a new tag. Simply move the tag 
creating part:


for i in soup.find_all(text='■'):
for ii in i.find_next_siblings():
if ii.name=='font' or str(ii).lstrip('')[0:1]=='/':
break
else:
if ii.name=='b':
tag = soup.new_tag('span')
tag['style'] = 'REPLACE'
tag.string=ii.string
    print(ii.replace_with(tag))

And please read
https://wiki.python.org/moin/GoogleGroupsPython
if you want to continue using Google Groups for accessing this list.

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: problem with graph of python(show)

2013-12-10 Thread Andreas Perstinger

On 10.12.2013 18:03, Asemaneh Allame wrote:

my mean is obvios
i cont get any graph of vpython
it shows me a maseage in this form:
" pythonw.exe has stopped working"
i m sure that have a good & perfect install and i dont khnow what s problem
is that enouph??


No, that's not enough. You need to be more specific.

How do you run your program? From the command line or some IDE? Or are 
you using the python shell?


What code are you trying to run?

How do you know that you have a "good & perfect install"?

Have you tried the example from the official site?
http://www.vpython.org/contents/bounce_example.html

There is also a forum for VPython:
https://groups.google.com/forum/?fromgroups&hl=en#!forum/vpython-users

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: using ffmpeg command line with python's subprocess module

2013-12-10 Thread Andreas Perstinger
iMath  wrote:
>we don't have permission to use the temporary file while it has not
>been closed,but when the file is closed , it will be destroyed by
>default(delete=True),but once we set delete=False,then we couldn't
>depend on the convenience of letting the temporary file automatically
>delete itself after it has been used(then we have to delete it later
>by os.remove()) ,thus there is nearly no convenience in creating a
>temporary file or a persistent one when using NamedTemporaryFile.

In your OP you asked for a platform independent solution thus I don't
think it's possible to do what you want if the OS doesn't support
opening a file another time while it's still open.

Otherwise, on my Linux system this works:

>>> import tempfile, subprocess
>>> with tempfile.NamedTemporaryFile() as fp:   
...   fp.write(b"foo\nbar\nbaz\n")
...   fp.flush()
...   subprocess.call(["cat", fp.name])
... 
12
foo
bar
baz
0

Bye, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: using ffmpeg command line with python's subprocess module

2013-12-04 Thread Andreas Perstinger
iMath  wrote:
>I use the following code to do the test ,but error occurred ,it
>prompts system cannot find specified files ,but the files are indeed
>exists there ,any help ?
>
>with tempfile.TemporaryFile() as fp:
>fp.write(("file '"+'a1.mp3'+"'\n").encode('utf-8'))
>fp.write(("file '"+'a2.mp3'+"'\n").encode('utf-8'))
>
>subprocess.call(['ffmpeg/ffmpeg', '-f', 'concat','-i',fp, '-c',
> 'copy', 'a3.mp3'])

Basic rule: Always copy'n'paste the exact traceback you get.

I don't think you are running the code you have posted because your
subprocess call doesn't work:

>>> import tempfile, subprocess
>>> with tempfile.TemporaryFile() as fp:
...   subprocess.call(["foo", "bar", fp, "baz"])
... 
Traceback (most recent call last):
  File "", line 2, in 
  File "/usr/lib/python3.3/subprocess.py", line 520, in call
with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.3/subprocess.py", line 820, in __init__
restore_signals, start_new_session)
  File "/usr/lib/python3.3/subprocess.py", line 1380, in _execute_child
restore_signals, start_new_session, preexec_fn)
TypeError: Can't convert '_io.BufferedRandom' object to str implicitly

"fp" is a file object, but subprocess expects a list of strings as
its first argument.

Bye, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question regarding 2 modules installed via 'pip'

2013-11-16 Thread Andreas Perstinger

On 16.11.2013 16:13, Ferrous Cranus wrote:

Τη Σάββατο, 16 Νοεμβρίου 2013 5:01:15 μ.μ. UTC+2, ο χρήστης Robert
Kern έγραψε:

The kind people at http://serverfault.com/ can help you with your
system administration problems. I'm afraid that we cannot.


Robert i have followed your advise and akse there the other time for
why yum cannot detect python and pip and what i should do.

i received no reply 2-3 days now.

> I will nto ask there again.

The only question I've found from you on serverfault

http://serverfault.com/questions/555054/python-pip-installation-under-centos-6-4

was answered within one hour (you asked at 2013-11-14 17:27:33Z,
"yoonix" answered at 2013-11-14 18:19:54Z). But since he didn't spoonfed
you, no wonder that you ignore that answer.

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Andreas Perstinger

On 02.11.2013 12:58, Nick the Gr33k wrote:

Trying to add the current filename into the existent 'downloads' column
Somehow i don't think i just use the plus sign into an existing column.
We don't try to add numbers here but add an extra string to an already
existing array of strings(list).


[SNIP]


# update specific visitor's download record
cur.execute('''UPDATE visitors SET downloads = downloads + %s WHERE host
= %s''', (filename, host) )
==


Well, when do you understand that your MySQL problems have nothing to do 
with Python?


Everything inside the triple quotes is MySQL specific, so it's a MySQL 
problem whether you can use + to "add an extra string to an already 
existing array of strings(list)".


This list is not a MySQL support forum.

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to get final URL after redirection

2013-10-31 Thread Andreas Perstinger
nishant bhakta  wrote:

>I have a link that will redirect to any-other link and i have to work
>with that final link. For example if i have a link "www.bit.ly/2V6CFi"
>that will redirect to "www.google.com". Here i want that i take
>"www.bit.ly/2V6CFi" and find the final redirect link and append
>"#q=python" to that link and produce an output that is
>"www.google.com/#q=python".

For bitly links you need to use their API:
http://dev.bitly.com/links.html#v3_expand

There is a python module for interacting with it:
https://github.com/bitly/bitly-api-python

Bye, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Python TkInter, GTK, GUI overall

2013-10-16 Thread Andreas Ecaz
I've been looking at TkInter and GTK to do some GUI programming, they're both 
cross-platform compatible.

This might seem like a stupid question, but, how do people run the application? 
I get that I have to compile it and make it an executable. But how do I make it 
an executable? For Windows and Linux?

And do the people who use the software need to have Python installed on their 
local machine?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: parsing email from stdin

2013-10-08 Thread Andreas Perstinger

On 08.10.2013 17:25, Antoon Pardon wrote:

Op 08-10-13 16:24, Andreas Perstinger schreef:

Looking at the docs, I've found there is also "message_from_binary_file"
which works for me with your code.

http://docs.python.org/3/library/email.parser.html#email.message_from_binary_file



I can't try that out right now, but I had a look at the code and the
ByteParser that is mentioned their looks like this:

class BytesFeedParser(FeedParser):
  """Like FeedParser, but feed accepts bytes."""

  def feed(self, data):
  super().feed(data.decode('ascii', 'surrogateescape'))


Somehow I doubt that trying to decode my utf-8 stream as if it was
ascii will work.


Actually it does work:

$ cat testmail.txt
From: "someone" 
To: "me" 
Subject: something
Content-Type: text/plain; charset="UTF-8";
Content-Transfer-Encoding: 8bit

foo bar AÄÖÜĎӅ baz

$ file testmail.txt
testmail.txt: news or mail, UTF-8 Unicode text

$ cat foo.py
#!/usr/bin/python3

import sys
from email import message_from_binary_file

sys.stdin = sys.stdin.detach()
msg = message_from_binary_file(sys.stdin)

print("from: ", msg['From'])
print("to: ", msg['To'])
print("subject: ", msg['Subject'])
print("body: ", msg.get_payload())

$ ./foo.py < testmail.txt
from:  "someone" 
to:  "me" 
subject:  something
body:  foo bar AÄÖÜĎӅ baz

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: parsing email from stdin

2013-10-08 Thread Andreas Perstinger

On 08.10.2013 14:20, Antoon Pardon wrote:

As I don't know what encoding these messages will be in, I thought it
would be prudent to read stdin as binary data.

Using python 3.3 on a debian box I have the following code.

#!/usr/bin/python3

import sys
from email import message_from_file

sys.stdin = sys.stdin.detach()
msg = message_from_file(sys.stdin)


Looking at the docs, I've found there is also "message_from_binary_file" 
which works for me with your code.


http://docs.python.org/3/library/email.parser.html#email.message_from_binary_file

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: Re for Apache log file format

2013-10-08 Thread Andreas Perstinger

On 08.10.2013 08:33, Sam Giraffe wrote:

#this is a single line
string = '192.168.122.3 - - [29/Sep/2013:03:52:33 -0700] "GET / HTTP/1.0"
302 276 "-" "check_http/v1.4.16 (nagios-plugins 1.4.16)"'

#trying to break up the pattern match for easy to read code
pattern = re.compile(r'(?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+'
  r'(?P\-)\s+'
  r'(?P\-)\s+'
  r'(?P\[(.*?)\])\s+'
  r'(?P\"(.*?)\")\s+'
  r'(?P\d{3})\s+'
  r'(?P\d+)\s+'
  r'(?P\"\")\s+'
  r'(?P\((.*?)\))')


[SNIP]


The python interpreter is skipping to the 'math = re.search' and then the
'if' statement right after it looks at the , instead of moving onto
 and so on.


I'm not sure if I understand your problem, but your regex pattern only 
matches up to the size. When you look for the referrer, the pattern 
expects two quotes but in your string you have "-" (quote, dash, quote). 
Thus there is no match (i.e. "match" is None) and the if-statement will 
print "not found".


Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to streamingly read text file and display whenever updated text

2013-10-07 Thread Andreas Perstinger

On 07.10.2013 03:54, galeom...@gmail.com wrote:

https://docs.google.com/file/d/0B2D69u2pweEvelh1T25ra19oZEU/edit?usp=sharing



For the readers who don't bother clicking on the link above: It's a 
short video where the OP demonstrates how her/his usage of tail doesn't 
work.



no matter call tail directly in python or using the script of tail
all failed
it seems it can not read next line


In your video you use gedit to write some file and "tail -f " to 
follow it. But "tail -f" will follow the file descriptor. Usually, 
editors like gedit won't save your changes to the original file but 
create a new temporary file and rename it later to the original file 
name after deleting the original one. Thus tail will follow an already 
deleted file.

See also this blog post:
http://tech.shantanugoel.com/2009/12/23/continuous-monitor-tail-fails.html

For your example you will have to use "tail -F " which will follow 
the file name.


Alternatively you could write a simple script to simulate a continously 
growing file like


import time
for i in range(1000):
with open("test.txt", "a") as f:
f.write(str(i) + '\n')
time.sleep(1)

which should work with "tail -f".

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: Select fails when cookie tried to get a numeric value

2013-10-05 Thread Andreas Perstinger

On 05.10.2013 16:24, Νίκος Αλεξόπουλος wrote:

# initialize cookie
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )


Watch:

>>> cookie1 = cookies.SimpleCookie('ID=42')
>>> cookie1.load(cookie1)
>>> print(cookie1)
Set-Cookie: ID="Set-Cookie: ID=42"
>>> cookie1.get('ID').value
'Set-Cookie: ID=42'

And now watch this:

>>> cookie2 = cookies.SimpleCookie('ID=42')
>>> print(cookie2)
Set-Cookie: ID=42
>>> cookie2.get('ID').value
'42'

Explanation:

http://docs.python.org/3/library/http.cookies.html#http.cookies.BaseCookie.load

>>> c = cookies.SimpleCookie('ID=42')
>>> isinstance(c, dict)
True
>>> c.items()
dict_items([('ID', )])

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: Select fails when cookie tried to get a numeric value

2013-10-05 Thread Andreas Perstinger

On 05.10.2013 17:31, Νίκος Αλεξόπουλος wrote:

Now i have it like this:

# connect to database
con = pymysql.connect( db = 'nikos_metrites', user = 'nikos_root',
passwd = 't1abhp2r!', charset = 'utf8', host = 'localhost' )


Just to be sure: That's not your real password, is it?

Bye, Andreas

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-28 Thread Andreas Perstinger
Νίκος  wrote:

>Στις 28/9/2013 1:19 μμ, ο/η Chris Angelico έγραψε:
>> [ROLL] Rosuav rolls his eyes: 1, 1, totalling 2.
>>
>> Then split your try blocks! You've already been told this.
>>
>No we didn't have said this. if you are referring to this:

At least Denis told you about 24 hours ago:
https://mail.python.org/pipermail/python-list/2013-September/656318.html

So either do it like that (which is the reasonable way) or look for
another programming language.

Bye, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird bahaviour from shlex - line no

2013-09-28 Thread Andreas Perstinger

On 28.09.2013 08:26, Daniel Stojanov wrote:

Can somebody explain this. The line number reported by shlex depends
on the previous token. I want to be able to tell if I have just popped
the last token on a line.


[SNIP]


second = shlex.shlex("word1 word2,\nword3")


Punctuation characters like the comma are not considered as word 
characters by default and thus are seen as different tokens (consisting 
of only a single character):


>>> lexer = shlex.shlex("foo, bar, ...")
>>> token = lexer.get_token()
>>> while token != lexer.eof:
...   print token
...   token = lexer.get_token()
...
foo
,
bar
,
.
.
.

If you want to treat them as "word" characters you need to add them to 
the string "wordchars" (a public attribute of the "shlex" instance):


>>> lexer = shlex.shlex("foo.bar, baz")
>>> lexer.wordchar += '.,'
>>> print lexer.get_token()
foo.bar,
>>> print lexer.get_token()
baz

There is also a "debug" attribute (with three different levels: 1, 2, 3; 
default value 0 means no debug output):


>>> lexer = shlex.shlex("foo, bar, ...")
>>> lexer.debug = 1
>>> print lexer.get_token()
shlex: token='foo'
foo
>>> print lexer.get_token()
shlex: popping token ','
,

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: print function and unwanted trailing space

2013-08-31 Thread Andreas Perstinger

On 31.08.2013 10:17, candide wrote:


What is the equivalent in Python 3 to the following Python 2 code:

# -
for i in range(5):
  print i,
# -

?


How about

>>> print(" ".join(str(i) for i in range(5)))
0 1 2 3 4

Bye, Andreas



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


Re: Moving to Python for web

2013-08-29 Thread Andreas Ecaz
On Thursday, August 29, 2013 3:10:03 PM UTC+2, Chris “Kwpolska” Warrick wrote:
> On Thu, Aug 29, 2013 at 2:45 PM, Andreas Ecaz  wrote:
> 
> > I've decided to go with Flask! It's now running on UWSGI with NGINX. 
> > Hopefully I can get some stuff done :)
> 
> 
> 
> How are you running uWSGI?  On sane (non-Windows) OSes, I recommend
> 
> using the uWSGI Emperor, which will protect you from your website
> 
> going down when something crashes.  You run the Emperor through your
> 
> OS’s init system (e.g. upstart in Ubuntu, systemd in many others).
> 
> 
> 
> -- 
> 
> Chris “Kwpolska” Warrick <http://kwpolska.tk>
> 
> PGP: 5EAAEA16
> 
> stop html mail | always bottom-post | only UTF-8 makes sense

Well, I know I'm not using Emperor. I'm fairly new to managing servers myself 
but I'll take a look at how to set that up.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving to Python for web

2013-08-29 Thread Andreas Ecaz
I've decided to go with Flask! It's now running on UWSGI with NGINX. Hopefully 
I can get some stuff done :)


@Chris “Kwpolska” Warrick

I just don't like the big frameworks, for me there is too much magic going on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving to Python for web

2013-08-28 Thread Andreas Ecaz
On Wednesday, August 28, 2013 11:25:44 PM UTC+2, Andreas Ecaz wrote:
> I've looked at Flask, Bottle and Web.py. I quite like the look of Bottle. 
> I'll keep looking for some other microframeworks, maybe I can find something 
> else that interests me.
> 
> 
> 
> Thank you.

At the moment I'm worried about writing more framework than python (if that 
makes sense) which seems unlikely with MOST microframeworks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving to Python for web

2013-08-28 Thread Andreas Ecaz
On Wednesday, August 28, 2013 11:08:52 PM UTC+2, Joel Goldstick wrote:
> On Wed, Aug 28, 2013 at 4:14 PM,   wrote:
> 
> > So, I have been working in PHP for several years but I want to learn 
> > something new. That something new is Python. But since I'm a web developer 
> > I want to build stuff for the web.
> 
> >
> 
> > I don't want to use Django because it's too bloated, it seem to do 
> > everything for you. I don't like that. I want to do the "plumbing". But at 
> > the same time I have no idea how I would write something that could handle 
> > cookies, sessions, post, get etc etc; so I assume I have to use some kind 
> > of web framework.
> 
> >
> 
> > So, can you recommend a minimal web framework that still allows me to write 
> > in Python? Furthermore, do I even need one? I am currently running NGINX 
> > and I have UWSGI installed. I'm just worried about how I would handle form 
> > submissions, get requests and sessions/cookies.
> 
> >
> 
> > Any advice would be greatly appreciated.
> 
> 
> 
> I like django, but you may want to google "python micro web framework"
> 
> 
> 
> There are a handful with some following so that there are communities,
> 
> docs, etc available
> 
> 
> 
> As to get/cookies/sessions check out the requests module (3rd party -
> 
> well received) http://docs.python-requests.org/en/latest/
> 
> > --
> 
> > http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Joel Goldstick
> 
> http://joelgoldstick.com

I've looked at Flask, Bottle and Web.py. I quite like the look of Bottle. I'll 
keep looking for some other microframeworks, maybe I can find something else 
that interests me.

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


Re: Question about mailing list rules

2013-07-12 Thread Andreas Perstinger

On 12.07.2013 01:59, Devyn Collier Johnson wrote:

Am I allowed to ask questions like "Here is my code. How can I optimize
it?" on this mailing list?


If it's written in Python, why not?

But that doesn't mean you are guaranteed to get an answer :-).

And please read http://sscce.org/ before posting your latest 10,000 line 
program :-)


Bye, Andreas

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


Re: A few questiosn about encoding

2013-06-20 Thread Andreas Perstinger
Rick Johnson  wrote:
>
> Since we're on the subject of Unicode:
>
>One the most humorous aspects of Unicode is that it has
>encodings for Braille characters. Hmm, this presents a
>conundrum of sorts. RIDDLE ME THIS?!
>
>Since Braille is a type of "reading" for the blind by
>utilizing the sense of touch (therefore DEMANDING 3
>dimensions) and glyphs derived from Unicode are
>restrictively two dimensional, because let's face it people,
>Unicode exists in your computer, and computer screens are
>two dimensional... but you already knew that -- i think?,
>then what is the purpose of a Unicode Braille character set?
>
>That should haunt your nightmares for some time.

>From http://www.unicode.org/versions/Unicode6.2.0/ch15.pdf
"The intent of encoding the 256 Braille patterns in the Unicode
Standard is to allow input and output devices to be implemented that
can interchange Braille data without having to go through a
context-dependent conversion from semantic values to patterns, or vice
versa. In this manner, final-form documents can be exchanged and
faithfully rendered."

http://files.pef-format.org/specifications/pef-2008-1/pef-specification.html#Unicode

I wish you a pleasant sleep tonight.

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me with the script? How to find items in csv file A and not in file B and vice versa

2013-06-18 Thread Andreas Perstinger
alonn...@gmail.com wrote:
>and when I run it I get an invalid syntex error and (as a true newbie
>I used a GUI)in_a_not_b is highlighted in the with open("inAnotB.csv",
>"wb") as f: 
>writer = csv.writer(f) 
>writer.writerows([item] for item in_a_not_b)
 

The syntax for the for-clause in a comprehension is

for x in something

thus you are missing the "in" keyword:

writer.writerows([item] for item in in_a_not_b)

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: C vs Python terminology

2013-06-16 Thread Andreas Perstinger

On 16.06.2013 14:55, Dave Angel wrote:

On 06/16/2013 07:22 AM, Andreas Perstinger wrote:

On 16.06.2013 08:32, Denis McMahon wrote:

C:

^



int a, b;
b = 6;
a = b;

In C, this places the numeric value 6 into the memory location identified

^


by the variable "b",


so far so good.


then copies the value from the location pointed to by "b" into the
location pointed to by "a".


Wrong. Neither "a" nor "b" are pointers, thus they don't point to a
memory location.
This part should be written as
"then copies the value at the location identified by "b" to the location
identified by "a".


But it doesn't.  It binds b to the same object to which a is currently
bound.


Are you aware that Denis was talking about the behaviour of C in the 
above quote?



b is a pointer to a memory location containing the value 6

 > a is a pointer to another memory location also containing the value 6

Again, neither "a" nor "b" are pointers.
"b" is the name of a memory location containing the integer value 6.
"a" is the name of another memory location containing the integer value 6.



Not even close.  If you don't like the terms "bound" or "points", the
perhaps you'd be happy with "b" is the name that currently knows how to
find an int object containing 6.  That object has no name, and never
will.  And it can exist for a long time with no names directly bound to it.


Again, Denis was talking about C.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


OT: C vs Python terminology (was: A certainl part of an if() structure never gets executed)

2013-06-16 Thread Andreas Perstinger

On 16.06.2013 08:32, Denis McMahon wrote:

C:

int a, b;
b = 6;
a = b;

In C, this places the numeric value 6 into the memory location identified
by the variable "b",


so far so good.


then copies the value from the location pointed to by "b" into the
location pointed to by "a".


Wrong. Neither "a" nor "b" are pointers, thus they don't point to a 
memory location.

This part should be written as
"then copies the value at the location identified by "b" to the location 
identified by "a".



b is a pointer to a memory location containing the value 6

> a is a pointer to another memory location also containing the value 6

Again, neither "a" nor "b" are pointers.
"b" is the name of a memory location containing the integer value 6.
"a" is the name of another memory location containing the integer value 6.


Python:

b = 6
a = b

In Python, this first puts the value 6 in in a memory location and points
"b" at that memory location, then makes "a" point to the same memory
location as "b" points to.

b is a pointer to a memory location containing the value 6
a is a pointer to the same memory location


I wouldn't use the term "pointer" in context with Python. Using the 
terms from the language reference I would write that as
"In Python, this first creates an integer object with value 6 and then 
binds the name "b" to it. Then it binds the name "a" to the same object.
Thus both "a" and "b" reference the same object, i.e. they are different 
names for the same object."


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Don't feed the troll...

2013-06-15 Thread Andreas Perstinger
Nick the Gr33k  wrote:
>You are spamming my thread.

Well, you don't own this thread. In fact nobody owns it. This is a
public forum and thus anybody can answer to any post as he likes.

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pattern Search Regular Expression

2013-06-15 Thread Andreas Perstinger
subhabangal...@gmail.com wrote:
>I know this solution but I want to have Regular Expression option.
>Just learning.

http://mattgemmell.com/2008/12/08/what-have-you-tried/

Just spell out what you want:
A word at the beginning, followed by any text, followed by a word at
the end.
Now look up the basic regex metacharacters and try to come up with a
solution (Hint: you will need groups)

http://docs.python.org/3/howto/regex.html#regex-howto
http://docs.python.org/3/library/re.html#regular-expression-syntax

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Having a hard time to 'get' bing api search results

2013-06-14 Thread Andreas Perstinger

On 14.06.2013 20:19, Yves S. Garret wrote:

This is the error that I'm getting right now.

import json
from pprint import pprint
path = '/home/azureuser/temp.json'
with open(path) as data_file:

...   data = json.load(data_file)
...
Traceback (most recent call last):
   File "", line 2, in 
   File "/usr/local/lib/python2.7/json/__init__.py", line 290, in load
 **kw)
   File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads
 return _default_decoder.decode(s)
   File "/usr/local/lib/python2.7/json/decoder.py", line 365, in decode
 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
   File "/usr/local/lib/python2.7/json/decoder.py", line 381, in raw_decode
 obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 2 column 1 (char 2)

Thanks for your inputs Andreas.

Also, this is my JSON file, I'll post again.  Since it's going to be
messy, I'll include a link as well (users can decide what they prefer
to read).
http://bin.cakephp.org/view/1050217914


Ok, I've just copied the text from the site into a file and there is no 
problem loading the file.


You could try the same.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Having a hard time to 'get' bing api search results

2013-06-13 Thread Andreas Perstinger

On 14.06.2013 03:00, Yves S. Garret wrote:

Thanks again Kevin.  I'm deviating from the original thread,
but I've got another issue.  When I try to load the json file
and then parse it, this is the error that I get:
http://bin.cakephp.org/view/1329549559


1) Please don't top post. Put your answer after the parts you are 
replying to.


2) Is Kevin sending his e-mails only to you? I don't get them and they 
aren't in the mailing list archive either.


3) Please copy the traceback you get into your message. Otherwise you 
will reduce the amount of people who are willing to help you because not 
everyone likes to go to an external website just to read them.

So here's it:

>>> import json
>>> import pprint
>>> json_data = open('temp.json')
>>> data = json.load(json_data)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/json/__init__.py", line 290, in load
**kw)
  File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 2 column 1 (char 2)

4) The error message tells you that json.load() can't parse your file 
due to an error at the beginning of line 2. So can you please post the 
first lines of your file?


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Andreas Perstinger

On 13.06.2013 20:10, Nick the Gr33k wrote:
[nothing new]

Could you please stop spamming the whole internet with your problems.
Not only that you've posted two similar offtopic messages within only 6 
minutes to this list, you've also crossposted to alt.os.linux (where it 
is offtopic too) and to the forum at devshed.com (at least you've found 
the right subforum there).


Thank you very much!

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


Re: Wrong website loaded when other requested

2013-06-13 Thread Andreas Perstinger

On 13.06.2013 16:23, Νικόλαος Κούρας wrote:

Please suggest something of why this happnes.


That's not a Python problem.

BTW both scripts at
http://superhost.gr/~dauwin/metrites.py
and at
http://superhost.gr/~dauwin/cgi-bin/metrites.py
show the world the passwords to your databases in plain text.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-13 Thread Andreas Perstinger

On 13.06.2013 02:59, rice.cr...@gmail.com wrote:

I am parsing the output of an open-iscsi command that contains
severalblocks of data for each data set. Each block has the format:

[SNIP]

I tried using \s* to swallow the whitespace between the to iSCSI
lines. No joy... However [\s\S]*? allows the regex to succeed. But that
seems to me to be overkill (I am not trying to skip lines of text here.)
Also note that I am using \ + to catch spaces between the words. On the
two problem lines, using \s+ between the label words fails.


Changing

 # Connection state
 iSCSI\ +Connection\ +State:\s+(?P\w+\s*\w*)
 [\s\S]*?<<<<<< without this the regex fails
 # Session state
 iSCSI\ +Session\ +State:\s+(?P\w+)


to
# Connection state
iSCSI\s+Connection\s+State:\s+(?P\w+\s*\w*)\s*
# Session state
iSCSI\s+Session\s+State:\s+(?P\w+)

gives me

>>> # 'test' is the example string
>>> myDetails = [ m.groupdict() for m in regex.finditer(test)]
>>> print myDetails
[{'initiatorIP': '221.128.52.214', 'connState': 'LOGGED IN', 'SID': 
'154', 'ipaddr': '221.128.52.224', 'initiatorName': 
'iqn.1996-04.de.suse:01:7c9741b545b5', 'sessionState': 'LOGGED_IN', 
'iqn': 'iqn.1992-04.com.emc:vplex-8460319f-00000007', 
'tag': '7', 'port': '3260'}]


for your example (same for the original regex).
It looks like it works (Python 2.7.3) and there is something else 
breaking the regex.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Andreas Perstinger

[Please trim your replies to the relevant parts.]

On 12.06.2013 10:54, Νικόλαος Κούρας wrote:

But when it comes to select '==' from month instead of
'==' to be submitted a zero gets submitted and i think the
problem is the way i'm filling up months into the drop down menu which is:


for i, month in enumerate(months):
  print(' %s ' % (i, month) )


the if case does not execute because of the way it checks for None entry
which is: elif '=' not in year:

but if enumerate yields 0 instead of '==' then elif '=' not in
year of course fails.


How often do we need to tell you that you should reread your posts 
before sending them?
You start with telling us you have problems with "month" and then show 
us code regarding "year"



So, i must tell:

for i, month in enumerate(months):
  print(' %s ' % (i, month) )

to somehow return '==' instead of 0 but don't know how.


As with most of your problems you are barking up the wrong tree.
Why not use the actual value you get from the form to check whether you 
have a valid month?

Do you understand why "0" is submitted instead of "=="?

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: e-mail reply to old/archived message

2013-06-11 Thread Andreas Perstinger

On 11.06.2013 22:14, Νικόλαος Κούρας wrote:

Τη Τρίτη, 11 Ιουνίου 2013 2:21:50 μ.μ. UTC+3, ο χρήστης Andreas Perstinger 
έγραψε:

> sending the mail to python-list@python.org will just open anew
> subject intead of replyign to an opened thread.



You would need to find out the Message-Id of the post you want to reply
to and then add manually the In-Reply-To and References headers to your
e-mail using that Id.


You mean by viewing for example your post as 'view original source', finding
In-Reply-To: <71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com>


No, the In-Reply-To header in *my* post is the post *I* have replied to, 
i.e. that's the Message-ID of *your* earlier post.




and then compose a new mail as:

to: Andreas Perstinger 
cc: In-Reply-To: <71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com>

is this the way Andrea?


No, the headers would be:
To: python-list@python.org
In-Reply-To: <51b7084e.9040...@gmail.com>
References:  
<51b5bb53$0$29997$c3e8da3$54964...@news.astraweb.com> 
<71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com> 
<51b7084e.9040...@gmail.com>


Basically, you should follow RFC 2822 and RFC 1036 if you don't mess up 
with message threading.


You also need to know that you can't add these headers manually in 
Thunderbird out of the box. You would need to edit the configuration.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Receing a form variable as a list instead of as a string

2013-06-11 Thread Andreas Perstinger

On 11.06.2013 12:38, Νικόλαος Κούρας wrote:

but page is a form variable coming from a previous sumbitted form
why the error says 'page' is a list?


RTFM:
"If the submitted form data contains more than one field with the same 
name, the object retrieved by form[key] is not a FieldStorage or 
MiniFieldStorage instance but a list of such instances. Similarly, in 
this situation, form.getvalue(key) would return a list of strings."

http://docs.python.org/3.3/library/cgi.html#using-the-cgi-module

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


OT: e-mail reply to old/archived message (was Re: Encoding questions (continuation))

2013-06-11 Thread Andreas Perstinger

On 10.06.2013 15:56, Νικόλαος Κούρας wrote:

Τη Δευτέρα, 10 Ιουνίου 2013 2:41:07 μ.μ. UTC+3, ο χρήστης Steven
D'Aprano έγραψε:

On Mon, 10 Jun 2013 14:13:00 +0300, Νικόλαος Κούρας wrote:

ps. i tried to post a reply to the thread i opend via thunderbird
mail client, but not as a reply to somne other reply but as  new
mail send to python list. because of that a new thread will be
opened. How can i tell thunderbird to reply to the original
thread and not start a new one?

By replying to an email in that thread.


Yes thats obvious. What is not obvious is how you reply back to a
thread by giving extra info when you are not replying to a mail formt
tha thread or when you ahve deleted the reply for a member

sending the mail to python-list@python.org will just open anew
subject intead of replyign to an opened thread.


You would need to find out the Message-Id of the post you want to reply 
to and then add manually the In-Reply-To and References headers to your 
e-mail using that Id.


It's probably easier to just use the web interface at Gmane.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Andreas Perstinger

On 10.06.2013 11:59, Νικόλαος Κούρας wrote:

>>>> s = 'α'
>>>> s.encode('utf-8')
> b'\xce\xb1'


'b' stands for binary right?


No, here it stands for bytes:
http://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals


  b'\xce\xb1' = we are looking at a byte in a hexadecimal format?


No, b'\xce\xb1' represents a byte object containing 2 bytes.
Yes, each byte is represented in hexadecimal format.


if yes how could we see it in binary and decimal represenation?


>>> s = b'\xce\xb1'
>>> s[0]
206
>>> bin(s[0])
'0b11001110'
>>> s[1]
177
>>> bin(s[1])
'0b10110001'

A byte object is a sequence of bytes (= integer values) and support 
indexing.

http://docs.python.org/3/library/stdtypes.html#bytes


Since 2^8 = 256, utf-8 should store the first 256 chars of unicode
charset using 1 byte.

Also Since 2^16 = 65535, utf-8 should store the first 65535 chars of
unicode charset using 2 bytes and so on.

But i know that this is not the case. But i dont understand why.


Because your method doesn't work.
If you use all possible 256 bit-combinations to represent a valid 
character, how do you decide where to stop in a sequence of bytes?



>>>> s = 'a'
>>>> s.encode('utf-8')
> b'a'
utf-8 takes ASCII as it is, as 1 byte. They are the same


EBCDIC and ASCII and Unicode are charactet sets, correct?

iso-8859-1, iso-8859-7, utf-8, utf-16, utf-32 and so on are encoding methods, 
right?



Look at http://www.unicode.org/glossary/ for an explanation of all the 
terms.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Andreas Perstinger

On 10.06.2013 09:10, nagia.rets...@gmail.com wrote:

Τη Κυριακή, 9 Ιουνίου 2013 3:31:44 μ.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε:


py> c = 'α'
py> ord(c)
945


The number 945 is the characters 'α' ordinal value in the unicode charset 
correct?


Yes, the unicode character set is just a big list of characters. The 
946th character in that list (starting from 0) happens to be 'α'.



The command in the python interactive session to show me how many bytes
this character will take upon encoding to utf-8 is:


s = 'α'
s.encode('utf-8')

b'\xce\xb1'

I see that the encoding of this char takes 2 bytes. But why two exactly?


That's how the encoding is designed. Haven't you read the wikipedia 
article which was already mentioned several times?



How do i calculate how many bits are needed to store this char into bytes?


You need to understand how UTF-8 works. Read the wikipedia article.


Trying to to the same here but it gave me no bytes back.


s = 'a'
s.encode('utf-8')

b'a'


The encode method returns a byte object. It's length will tell you how 
many bytes there are:


>>> len(b'a')
1
>>> len(b'\xce\xb1')
2

The python interpreter will represent all values below 256 as ASCII 
characters if they are printable:


>>> ord(b'a')
97
>>> hex(97)
'0x61'
>>> b'\x61' == b'a'
True

The Python designers have decided to use b'a' instead of b'\x61'.


py> c.encode('utf-8')
b'\xce\xb1'


2 bytes here. why 2?


Same as your first question.


py> c.encode('utf-16be')
b'\x03\xb1'


2 byets here also. but why 3 different bytes? the ordinal value of
char 'a' is the same in unicode. the encodign system just takes the
ordinal value end encode, but sinc eit uses 2 bytes should these 2 bytes
be the same?


'utf-16be' is a different encoding scheme, thus it uses other rules to 
determine how each character is translated into a byte sequence.



py> c.encode('iso-8859-7')
b'\xe1'


And also does '\x' means that the value is being respresented in hex way?
and when i bin(6) i see '0b101'

I should expect to see 8 bits of 1s and 0's. what the 'b' is tryign to say?

'\x' is an escape sequence and means that the following two characters 
should be interpreted as a number in hexadecimal notation (see also the 
table of allowed escape sequences: 
http://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals 
).


'0b' tells you that the number is printed in binary notation.
Leading zeros are usually discarded when a number is printed:
>>> bin(70)
'0b1000110'
>>> 0b100110 == 0b00100110
True
>>> 0b100110 == 0b00100110
True

It's the same with decimal notation. You wouldn't say 00123 is different 
from 123, would you?


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Andreas Perstinger

On 09.06.2013 11:38, Νικόλαος Κούρας wrote:

s = 'α'
s = s.encode('iso-8859-7').decode('utf-8')
print( s )

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 0: 
unexpected end of data

Why this error? because 'a' ordinal value > 127 ?


>>> s = 'α'
>>> s.encode('iso-8859-7')
b'\xe1'
>>> bin(0xe1)
'0b1111'

Now look at the table on https://en.wikipedia.org/wiki/UTF-8#Description 
to find out how many bytes a UTF-8 decoder expects when it reads that value.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Source code as text/plain

2013-06-04 Thread Andreas Perstinger

On 04.06.2013 00:34, Carlos Nepomuceno wrote:



Date: Mon, 3 Jun 2013 09:06:46 +1000
From: c...@zip.com.au
To: c...@rebertia.com

[...]

http://hg.python.org/cpython/raw-file/tip/Lib/string.py


What's the 'tip' tag?   


http://hg.python.org/cpython/help/tip

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: netcdF4 variables

2013-06-01 Thread Andreas Perstinger

On 01.06.2013 05:30, Sudheer Joseph wrote:

some hing like a list
xx=nc,variables[:]
should get me all variable names with out other surrounding stuff??

In [4]: ncf.variables
Out[4]: OrderedDict([(u'LON', ),

[SNIP]

It looks like "variables" is an OrderedDict. Thus

>>> ncf.variables.keys()

should return a view (or list, depending on your python version) of all 
keys, i.e. all variable names.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-24 Thread Andreas Perstinger

On 24.05.2013 17:25, Carlos Nepomuceno wrote:



Date: Thu, 23 May 2013 19:29:14 -0700
Subject: Re: PEP 378: Format Specifier for Thousands Separator
From: dihedral88...@gmail.com
[some typical dihedral stuff]


I'm sorry but I don't understand your question.


Don't worry. I guess most people on this list don't understand it either.

It looks like dihedral is a bot although nobody knows for sure. Search 
for some other posts from him/her/it in the archive and form your own 
opinion.


IMHO you can simply ignore him/her/it.

Bye, Andreas

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


Re: Illegal seek error with seek() and os.lseek()

2013-05-14 Thread Andreas Perstinger

On 14.05.2013 21:00, krishna2pra...@gmail.com wrote:

  # first, open the file as a plain binary
  try:
  self.file = open(/dev/relpcfpga, "r+b", buffering=0)


Aren't you missing the quotes for "/dev/relpcfpga"?


The method seek() complains "OSError: [Errno 29] Illegal seek"
The device relpcfpga is a char device.


Are you sure that your device is seekable?
Try

f = open("/dev/relpcfpga", "r+b", buffering=0)
print(f.seekable())

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: global variable not working inside function. Increment

2013-05-13 Thread Andreas Perstinger
"feather.duster.kung.fu"  wrote:
>I'm just learning Python and NONE of the tutorials I read said
>anything about that . In fact they all say a global can be called from
>inside a Function. If possible please contact the ppl that write these
>things.

Well, we don't know which tutorials you read.
So why don't you tell them yourself?

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in "Import gv " module

2013-04-22 Thread Andreas Perstinger

You are still top posting.

On 22.04.2013 14:43, Megha Agrawal wrote:

yes, I did. They said, gv module doesn't exist for windows.


Then I'm afraid you are out of luck.

Two possible alternatives:

1) Save your graph to a file and use the command line tools:
http://stackoverflow.com/a/12698636

2) Try some other Graphviz bindings. A quick search on PyPi gave me:
https://pypi.python.org/pypi/pygraphviz/1.1
https://pypi.python.org/pypi/pydot/1.0.28
https://pypi.python.org/pypi/yapgvb/1.2.0

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error in "Import gv " module

2013-04-22 Thread Andreas Perstinger

Please avoid top posting and answer to the list.

On 22.04.2013 12:38, Megha Agrawal wrote:

Widows 7, and i have pygraphviz library in python27-> lib->
site-package folder.


Sorry don't know much about Windows.

Have you read through all the issues involving "import gv" errors?:
https://code.google.com/p/python-graph/issues/list?can=1&q=import+gv&colspec=ID+Type+Status+Priority+Milestone+Owner+Summary&cells=tiles

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error in "Import gv " module

2013-04-22 Thread Andreas Perstinger

On 22.04.2013 12:13, Megha Agrawal wrote:

https://code.google.com/p/python-graph/wiki/Example

When I am trying to run the code to draw a graph, given on above link, I am
getting following error:

ImportError: No module named gv

What can be the reasons?


Which OS?

It looks like you are missing "graphviz" or you need to adapt your paths:
https://code.google.com/p/python-graph/issues/detail?id=15

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-17 Thread Andreas Abel

On 17.04.2013 11:30, Uday S Reddy wrote:

Mark Janssen writes:


From:  en.wikipedia.org: Programming_paradigm:

"A programming paradigm is a fundamental style of computer
programming. There are four main paradigms: object-oriented,
imperative, functional and declarative. Their foundations are distinct
models of computation: Turing machine for object-oriented and
imperative programming, lambda calculus for functional programming,
and first order logic for logic programming."


I removed the second sentence relating paradigms to computation models
and put it on the talk page instead.  It does not make sense to connect 
imperative programming to Turing machines like functional programming to 
lambda calculus.  A better match would be random access machines, but 
the whole idea of a connection between a programming paradigm and a 
computation model is misleading.



While I understand the interest in purely theoretical models, I wonder
two things:  1)  Are these distinct models of computation valid?  And,
2) If so, shouldn't a theory of types announce what model of
computation they are working from?


These distinctions are not fully valid.

- Functional programming, logic programming and imperative programming are
three different *computational mechanisms*.

- Object-orientation and abstract data types are two different ways of
building higher-level *abstractions*.

The authors of this paragraph did not understand that computational
mechanisms and higher-level abstractions are separate, orthogonal dimensions
in programming language design.  All six combinations, obtained by picking a
computational mechanism from the first bullet and an abstraction mechanism
from the second bullet, are possible.  It is a mistake to put
object-orientation in the first bullet.  Their idea of "paradigm" is vague
and ill-defined.

Cheers,
Uday Reddy




--
Andreas Abel  <><  Du bist der geliebte Mensch.

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

andreas.a...@ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Plot in Python

2013-03-16 Thread Andreas Perstinger
subhabangal...@gmail.com wrote:
>I was trying to draw in Matplotlib but did not find much help.

Have you looked already at the homepape for "maptlotlib"?:
http://matplotlib.org/index.html

There you'll find a tutorial:
http://matplotlib.org/users/pyplot_tutorial.html

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Andreas Perstinger
Lele Gaifax  wrote:
>Ferrous Cranus  writes:
>
>> Let me ask it like this:
>> How can i avoid using try: except: for checkign the date but instead
>> check it with an if statement:
>
>Let me answer this way: you can't, without resorting to the simple
>helper functions I wrote in my previous message. 
>
>Why do you dislike that solution?

Ferrous Cranus has proven in previous discussions (search the archives)
that he doesn't like common-sense solutions and insists on doing it his
own way (although his methods are either wrong or impossible).

Don't waste your time.

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python launcher (PEP 397) and emacs python-mode.el

2013-01-31 Thread Andreas Röhler

Am 01.02.2013 00:59, schrieb Vinay Sajip:

Thomas Heller  ctypes.org> writes:


What I meant to write is this:

when the shebang line in script.py contains this:
#!/usr/bin/python3.1-32
then emacs SHOULD run
py.exe -3.1-32 script.py
and the launcher runs
c:\Python31\python.exe script.py


IMO it would be better for emacs to just run

py.exe script.py

and py.exe can read the shebang and do the right thing. This saves the emacs 
code
from having to duplicate the shebang line processing logic that py.exe uses
(which, as we know, is unusual. So for a cross-platform you can have a shebang
line of #!/usr/bin/python3.2, and on Windows it will still call the appropriate
Python 3.2 even if it's not in /usr/bin, as there's no /usr/bin :-))

Regards,

Vinay Sajip





https://bugs.launchpad.net/python-mode/+bug/1112207
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python launcher (PEP 397) and emacs python-mode.el

2013-01-31 Thread Andreas Röhler

Am 31.01.2013 17:35, schrieb Thomas Heller:

Am 31.01.2013 12:05, schrieb Andreas Röhler:

Am 31.01.2013 10:03, schrieb Thomas Heller:

Has someone managed to patch python-mode.el to use
the PEP 397 python launcher when you hit C-c C-c?

It seems that emacs should parse the shebang line in the edited
python script and pass the corresponding arguments to py.exe.



Yes, that's the way python-mode.el acts by default.

AFAIU that launcher is implemented in Python3.3 and should not need any
patch at all.
Should it not work, please file a bug-report at

https://bugs.launchpad.net/python-mode


Well, let me make these remarks:

1. I'm on Windows, using gnu-emacs 24.2.1, and python-mode.el 6.1.0.
I do not understand how the shebang line is used by python-mode.el,


it uses py-shebang-regexp to determine
- if a shebang is given
- if, yes, which interpreter to run


depending on what I write into it either 'python.exe' is started when
I hit C-c C-c, or I get 'Spawning child process: invalid argument'.
The latter occurs most often when the shebang string contains 'jython'.


please file a bug-report giving some example script which triggers the bug




2. I would like to use the PEP 397 python launcher to start the python
version that is specified in the shebang line.
The python launcher py.exe parses this line when I run 'py script.py',
and then starts the corresponding python interpreter version.
The launcher parses the shebang line by its own rules (see pep397 for
exact details).  One example is this:


#!/usr/bin/python3.1-32
import sys; print(sys.version)


The python launcher starts 'c:\Python31\python.exe -3.1-32 script.py'.



unfortunatly don't have a windows at my disposal.

At linux it would run exactly the interpreter specified. Might be okay for 
windows as shown.



I would like emacs to do the same; however this would require emacs
to do the same shebang line parsing as the launcher does.



So we do - looks like python-mode.el precedes PEP 397  :)

Expecting the bug elsewhere.


Thomas


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


Re: Python launcher (PEP 397) and emacs python-mode.el

2013-01-31 Thread Andreas Röhler

Am 31.01.2013 10:03, schrieb Thomas Heller:

Has someone managed to patch python-mode.el to use
the PEP 397 python launcher when you hit C-c C-c?

It seems that emacs should parse the shebang line in the edited
python script and pass the corresponding arguments to py.exe.



Yes, that's the way python-mode.el acts by default.

AFAIU that launcher is implemented in Python3.3 and should not need any patch 
at all.
Should it not work, please file a bug-report at

https://bugs.launchpad.net/python-mode

Andreas


Thomas





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


Re: How to tell people to ask questions the smart way

2012-09-05 Thread Andreas Perstinger

On 05.09.2012 01:05, Ben Finney wrote:

Andreas Perstinger  writes:


On 04.09.2012 11:34, Paolo wrote:
> how do I know if a JTextField has the focus?
> thank to all

Look there:
http://www.catb.org/esr/faqs/smart-questions.html#forum


That is an unhelpful response.


So we have to agree to disagree.

EOD.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: focus on jtextfield

2012-09-04 Thread Andreas Perstinger

On 04.09.2012 11:34, Paolo wrote:

how do I know if a JTextField has the focus?
thank to all


Look there:
http://www.catb.org/esr/faqs/smart-questions.html#forum

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cut out XML subtree

2012-08-29 Thread Andreas Perstinger
On Wed, 29 Aug 2012 18:17:18 +0200 
Florian Lindner  wrote:
> I want to cut out an XML subtree like that:
[snip] 
> Is there a way I can do that using etree or DOM? The first is
> prefered...

Python 3.2.2 (default, Sep  5 2011, 22:09:30) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.etree.ElementTree as etree
>>> test = """
... 
... 
... Element A.1
... Element A.2
... 
... 
... Element B.1
... Element B.2
... 
... """
>>> tree = etree.fromstring(test)
>>> subA = tree.find("subA")
>>> tree.remove(subA)
>>> new = etree.tostring(tree, encoding="unicode")
>>> print(new)


Element B.1
Element B.2



Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python list archives double-gzipped?

2012-08-27 Thread Andreas Perstinger

On 27.08.2012 03:40, Tim Chase wrote:

So it looks like some python-list@ archiving process is double
gzip'ing the archives.  Can anybody else confirm this and get the
info the right people?


In January, "random joe" noticed the same problem[1].
I think, Anssi Saari[2] was right in saying that there is something 
wrong in the browser or server setup, because I notice the same 
behaviour with Firefox, Chromium, wget and curl.


$ ll *July*
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 chromium_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug 27 13:41 curl_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 firefox_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug  2 03:27 wget_2012-July.txt.gz

The browsers get a double gzipped file (size 747850) whereas the 
download utilities get a normal gzipped file (size 748041).


After looking at the HTTP request and response headers I've noticed that 
the browsers accept compressed data ("Accept-Encoding: gzip, deflate") 
whereas wget/curl by default don't. After adding that header to 
wget/curl they get the same double gzipped file as the browsers do:


$ ll *July*
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 chromium_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug 27 13:41 curl_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:40 
curl_encoding_2012-July.txt.gz

-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 firefox_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug  2 03:27 wget_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 747850 Aug  2 03:27 
wget_encoding_2012-July.txt.gz


I think the following is happening:
If you send the "Accept-Encoding: gzip, deflate"-header, the server will 
gzip the file a second time (which is arguably unnecessary) and responds 
with "Content-Encoding: gzip" and "Content-Type: application/x-gzip" 
(which is IMHO correct according to RFC2616/14.11 and 14.17[3]).
But because many servers apparently don't set correct headers, the 
default behaviour of most browsers nowadays is to ignore the 
content-encoding for gzip files (application/x-gzip - see bug report for 
firefox[4] and chromium[5]) and don't uncompress the outer layer, 
leading to a double gzipped file in this case.


Bye, Andreas

[1] http://mail.python.org/pipermail/python-list/2012-January/617983.html

[2] http://mail.python.org/pipermail/python-list/2012-January/618211.html

[3] http://www.ietf.org/rfc/rfc2616

[4] https://bugzilla.mozilla.org/show_bug.cgi?id=610679#c5

[5] http://code.google.com/p/chromium/issues/detail?id=47951#c9
--
http://mail.python.org/mailman/listinfo/python-list


Re: help me debug my "word capitalizer" script

2012-08-22 Thread Andreas Perstinger

On 22.08.2012 08:21, Santosh Kumar wrote:

with open(givenfile) as file:
 # List to store the capitalised lines.
 lines = []
 for line in file:
 # Split words by spaces.
 words = line.split(' ')


The last element in your "words" list will still have a newline 
character appended to it.

You could probably use line.split().
See also the docs:
http://docs.python.org/py3k/library/stdtypes.html#str.split


 for i, word in enumerate(words):
 if len(word.strip(punctuation)) > 3:
 # Capitalise and replace words longer than 3 (without
punctuation)
 words[i] = word.capitalize()
 # Join the capitalised words with spaces.
 lines.append(' '.join(words))


This rebuilds the line including a newline character at the end.


 # Join the capitalised lines by the line separator
 capitalised = linesep.join(lines)


Because you haven't removed the newline character from each line, 
joining them with "linesep" introduces a second newline character after 
each line.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


RE: something about split()???

2012-08-14 Thread Andreas Tawn
> I have a question about the split function? surpose a = "|",and when I use 
> a.split("|") , I got the list
> ['"",""] ,but I want to get the empty list,what should I do ?

Something like...

>>> [x for x in "|".split("|") if x]
[]

Cheers,

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


Re: Beautiful Soup Table Parsing

2012-08-09 Thread Andreas Perstinger

On 09.08.2012 01:58, Tom Russell wrote:

For instance this code below:

soup = 
BeautifulSoup(urlopen('http://online.wsj.com/mdc/public/page/2_3021-tradingdiary2.html?mod=mdc_pastcalendar'))

table = soup.find("table",{"class": "mdcTable"})
for row in table.findAll("tr"):
 for cell in row.findAll("td"):
 print cell.findAll(text=True)

brings in a list that looks like this:


[snip]


What I want to do is only be getting the data for NYSE and nothing
else so I do not know if that's possible or not. Also I want to do
something like:

If cell.contents[0] == "Advances":
 Advances = next cell or whatever??---> this part I am not sure how to do.

Can someone help point me in the right direction to get the first data
point for the Advances row? I have others I will get as well but
figure once I understand how to do this I can do the rest.


To get the header row you could do something like:

header_row = table.find(lambda tag: tag.td.string == "NYSE")

From there you can look for the next row you are interested in:

advances_row = header_row.findNextSibling(lambda tag: tag.td.string == 
"Advances")


You could also iterate through all next siblings of the header_row:

for row in header_row.findNextSiblings("tr"):
 # do something

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-12 Thread Andreas Perstinger
On Thu, 12 Jul 2012 16:59:06 +1000 
Chris Angelico  wrote:

> On Thu, Jul 12, 2012 at 3:35 PM, Andreas Perstinger
>  wrote:
> > Do you mean this license?:
> > http://packages.python.org/PollyReports/license.html
> >
> > It's the standard license for NetBSD projects and approved by OSI:
> > http://www.opensource.org/licenses/bsd-license.php
> >
> > and GPL-compatible:
> > http://www.gnu.org/licenses/license-list.html#FreeBSD
> 
> Can you state that on the page, perhaps? It'd mean that anyone who's
> familiar with the license can read one keyword and know what the terms
> are, rather than dig through the full text to see if it's really the
> same or not.

I'm not responsible for any of the tree pages I've mentioned.

I've just looked at the "PollyReports"-license page because I was
curious which "strange" license the original author uses. Then I noticed
it's just one of the BSD-licenses, used Wikipedia to confirm it and
searched for the two other pages to show that it isn't problematic at
all.

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-11 Thread Andreas Perstinger
On Thu, 12 Jul 2012 10:41:52 +1000 
Simon Cropper  wrote:

> That said... with more than a passing interest in software and
> content licensing I looked at how the work was licensed. A
> none-standard license like this makes most people stop and think
> "will this be a problem if I use this in my work?" How compatible is
> your license with the main software licenses currently available?

Do you mean this license?:
http://packages.python.org/PollyReports/license.html

It's the standard license for NetBSD projects and approved by OSI:
http://www.opensource.org/licenses/bsd-license.php

and GPL-compatible:
http://www.gnu.org/licenses/license-list.html#FreeBSD

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-14 Thread Andreas Tawn
> p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal 
> interest (or
> perhaps both)?

We do use Python a fair bit, mostly for build systems and data mining, but also 
because it's the built-in script language for Motionbuilder.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> >> It's also helpful to not have to display every attribute, of which
> >> there may be dozens.
> >
> > Do I detect a code smell here?
> >
> I think so, Murphy's law dictates that the attribute you're interested in 
> will not be
> displayed anyway.

That's what __repr__'s for.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   >