Re: for / while else doesn't make sense

2016-05-24 Thread Gregory Ewing

Pete Forman wrote:

Gregory Ewing  writes:


Pete Forman wrote:


However I am coming from scientific measurements where 1.0 is the
stored value for observations between 0.95 and 1.05.


You only know that because you're keeping some extra information in
your head about what the 1.0 stored in your computer represents.


No, that is a real case. Floating point hardware can hold intermediate
values in 80 bit registers


I don't see how that's relevant. My point is that if all
you gave me was a file containing the IEEE representation
of a floating point 1.0 and no other information, I would
have no way of telling that you intended it to represent
a value between 0.95 and 1.05, as opposed to 0.9995 to
1.0005 or any other range. That's true regardless of
whether 32 bits, 64 bits or 80 bits is being used.

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


Re: for / while else doesn't make sense

2016-05-24 Thread Gregory Ewing

Christopher Reimer wrote:

Nope. I meant 8-bit ASCII (0-255).

http://www.ascii-code.com


That page is talking about latin-1, which is just one of many
possible 8-bit extensions of ascii.

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


Re: Question about imports and packages

2016-05-24 Thread Ben Finney
Gerald Britton  writes:

> On Wed, 25 May 2016 10:00 am, Steven D'Aprano wrote:
> >The problem is that you are running the Python script from *inside*
> >the package. That means, as far as the script can see, there is no
> >longer a package visible -- it cannot see its own outside from the
> >inside.
>
> Thanks for the explanation, Steven. I'm just having trouble
> reconciling this with the docs which seems to imply that an intra
> package import should work from inside the package.

The relative import will work fine inside a package.

The key difference is in *whether* your module is inside that package at
run time.

You have hit upon one of my primary complaints about Python. It makes
this normal mode of running a script::

python3 ./foo.py

not work properly, because Python in that case has no idea in which
package the module belongs. So it can't import other modules relative to
the current directory.

What the Python import system expects you to do is::

cd ../
python3 -m fnord.foo

To me, that makes Python at a *severe* handicap as a simple-to-use
scripting language.

But apparently “address a module by filesystem path” is severely
deprecated in Python. From that follows a lot of problems, such as this
one.


For more on traps with Python's import system, see
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html>

-- 
 \   “I cannot be angry at God, in whom I do not believe.” —Simone |
  `\   De Beauvoir |
_o__)  |
Ben Finney

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


Re: Question about imports and packages

2016-05-24 Thread Terry Reedy

On 5/24/2016 9:02 PM, Steven D'Aprano wrote:

On Wed, 25 May 2016 09:35 am, Gerald Britton wrote:

For brevity, here's your package setup:


testpkg/
+-- __init__.py
+-- testimport.py which runs "from testpkg.testimported import A"
+-- testimported.py containing class A

Your package layout is correct. But:


I have a similar setup, except with multiple files importing from 
imported file.  One way to make absolute imports within a package work, 
and how I do it, is to put the directory containing testpkg in a .pth 
file in the site-modules directory.  In particular, I have python.pth 
containing "F:/Python".  This effectively makes "Python" an extension of 
'site-packages', so when site-packages is searched for modules, so is 
Python.


--
Terry Jan Reedy

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


Question about imports and packages

2016-05-24 Thread Gerald Britton
On Wed, 25 May 2016 10:00 am, Steven D'Aprano wrote:
>On Wed, 25 May 2016 09:35 am, Gerald Britton wrote:
>
>For brevity, here's your package setup:
>
>
>testpkg/
>+-- __init__.py
>+-- testimport.py which runs "from testpkg.testimported import A"
>+-- testimported.py containing class A
>
>Your package layout is correct. But:
>
>> When I run
>>
>> python testimport.py
>>
>> I get:
>>
>> Traceback (most recent call last):
>> File "testimport.py", line 1, in 
>> from testpkg.testimported import A
>> ImportError: No module named testpkg.testimported
>
>The problem is that you are running the Python script from *inside* the
>package. That means, as far as the script can see, there is no longer a
>package visible -- it cannot see its own outside from the inside.
>
>cd to a directory *outside* the package, and run:
>
>python testpkg/testimport.py
>
>and it should work. Better: make sure the testpkg directory is somewhere in
>your PYTHONPATH, and run:
>
>python -m testpkg.testimport
>
>
>which tells Python to search for the package, rather than using a hard-coded
>path.
>
>
>The package directory has to be visible to the import system. That means it
>must be INSIDE one of the locations Python searches for modules. The
>current directory will do, but to be absolutely clear, that means that the
>package directory itself must be IN the current directory:
>
>
>./
>+-- pkgtest/
>+-- __init__.py
>+-- testimport.py
>+-- testimported.py
>
>
>Or you can use any other directory found in sys.path.
>
>
>
>--
>Steven

Thanks for the explanation, Steven.  I'm just having trouble
reconciling this with the docs which seems to imply that an intra
package import should work from inside the package.

This bit:

"When packages are structured into subpackages (as with the sound
package in the example), you can use absolute imports to refer to
submodules of siblings packages. For example, if the module
sound.filters.vocoder needs to use the echo module in the
sound.effects package, it can use from sound.effects import echo."

seems to say that what I was trying to do should work, since I'm
trying to use an absolute import to refer to a sibling module.  From
that I got the idea that the importer will ascend the package tree as
well as follow it down.

Or is the key idea here *submodule*? Since there are no modules in the
"sound" package in the example, only other packages?

FWIW this all came about when I was using pylint on a package where
the imports were relative.  Pylint tells me to add the package name as
the first qualifier (it warns about relative imports), which I tried
to do, only to find that doesn't work.

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


Re: Question about imports and packages

2016-05-24 Thread Steven D'Aprano
On Wed, 25 May 2016 09:35 am, Gerald Britton wrote:

For brevity, here's your package setup:


testpkg/
+-- __init__.py
+-- testimport.py which runs "from testpkg.testimported import A"
+-- testimported.py containing class A

Your package layout is correct. But:

> When I run
> 
> python testimport.py
> 
> I get:
> 
> Traceback (most recent call last):
> File "testimport.py", line 1, in 
> from testpkg.testimported import A
> ImportError: No module named testpkg.testimported

The problem is that you are running the Python script from *inside* the
package. That means, as far as the script can see, there is no longer a
package visible -- it cannot see its own outside from the inside.

cd to a directory *outside* the package, and run:

python testpkg/testimport.py

and it should work. Better: make sure the testpkg directory is somewhere in
your PYTHONPATH, and run:

python -m testpkg.testimport


which tells Python to search for the package, rather than using a hard-coded
path.


The package directory has to be visible to the import system. That means it
must be INSIDE one of the locations Python searches for modules. The
current directory will do, but to be absolutely clear, that means that the
package directory itself must be IN the current directory:


./
+-- pkgtest/
+-- __init__.py
+-- testimport.py
+-- testimported.py


Or you can use any other directory found in sys.path.



-- 
Steven

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


Re: multiprocessing not quite working

2016-05-24 Thread MRAB

On 2016-05-24 23:17, Noah wrote:


Hi,

I am using this example:
http://spartanideas.msu.edu/2014/06/20/an-introduction-to-parallel-programming-using-pythons-multiprocessing-module/

I am sending and receiving communication from the worker processes.

Two issues. the join is only getting to the process and waiting.
When I comment out the .join() process the output.get() appends the
previous process and therefore the returned output keeps getting longer
and longer after each process returns its output.

hostnames is an array of hostnames.

here is my code from main():

 # Define an output queue
 output = mp.Queue()

 # Setup a list of processes that we want to run
 processes = [mp.Process(target=worker, args=(hostnames[x], output))
for x in range(len(hostnames))]

 # Run processes
 for p in processes:
 print "start: {}".format(p)
 p.start()

 time.sleep(6)
 print "processes: {}".format(processes)

 # Exit the completed processes
 '''for p in processes:
 print "join: {}".format(p)
 p.join()'''

 print "got here"
 # Get process results from the output queue
 # results = [output.get() for p in processes]

 io = StringIO()
 count = 0
 for p in processes:
 found_output = output.get()
 print "returned {}".format(p)
 io.write (found_output)
 zipArchive.writestr(hostnames[count] + "." +
content['sitename'] + '.config.txt', io.getvalue())
 count = count + 1
 io.close()


def worker(hostname, output):
.
.
.
 output.put(template_output)



It says in the docs (Python 2.7, 16.6.2.2. Pipes and Queues):

"""Warning
As mentioned above, if a child process has put items on a queue (and it 
has not used JoinableQueue.cancel_join_thread), then that process will 
not terminate until all buffered items have been flushed to the pipe.


This means that *if you try joining that process you may get a deadlock 
unless you are sure that all items which have been put on the queue have 
been consumed*. Similarly, if the child process is non-daemonic then the 
parent process may hang on exit when it tries to join all its 
non-daemonic children.


Note that a queue created using a manager does not have this issue. See 
Programming guidelines.

"""

(Asterisks added to highlight.)

You should try to consume the output from a process before trying to 
join it (or, at least, join it without a timeout).


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


Question about imports and packages

2016-05-24 Thread Gerald Britton
I'm trying to understand packages in Python, especially Intra Package
References.

>From https://docs.python.org/2/tutorial/modules.html#packages i see that:

you can use absolute imports to refer to submodules of siblings packages.



This is what I can't get to work in my case. Here's the setup:

directory testpkg containing three files:
1. an empty __init__.py

2. a testimport.py which has:


from testpkg.testimported import A
a = A()
print type(a)

3. a testimported.py which has:


class A():
pass

When I run

python testimport.py

I get:

Traceback (most recent call last):
File "testimport.py", line 1, in 
from testpkg.testimported import A
ImportError: No module named testpkg.testimported

However, I thought I was doing what the doc describes for intra package
imports. What am I missing?

Or is the problem simply that I do not have subpackages?

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


multiprocessing not quite working

2016-05-24 Thread Noah


Hi,

I am using this example: 
http://spartanideas.msu.edu/2014/06/20/an-introduction-to-parallel-programming-using-pythons-multiprocessing-module/


I am sending and receiving communication from the worker processes.

Two issues. the join is only getting to the process and waiting.
When I comment out the .join() process the output.get() appends the 
previous process and therefore the returned output keeps getting longer 
and longer after each process returns its output.


hostnames is an array of hostnames.

here is my code from main():

# Define an output queue
output = mp.Queue()

# Setup a list of processes that we want to run
processes = [mp.Process(target=worker, args=(hostnames[x], output)) 
for x in range(len(hostnames))]


# Run processes
for p in processes:
print "start: {}".format(p)
p.start()

time.sleep(6)
print "processes: {}".format(processes)

# Exit the completed processes
'''for p in processes:
print "join: {}".format(p)
p.join()'''

print "got here"
# Get process results from the output queue
# results = [output.get() for p in processes]

io = StringIO()
count = 0
for p in processes:
found_output = output.get()
print "returned {}".format(p)
io.write (found_output)
zipArchive.writestr(hostnames[count] + "." + 
content['sitename'] + '.config.txt', io.getvalue())

count = count + 1
io.close()


def worker(hostname, output):
.
.
.
output.put(template_output)


Cheers

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


batch files and path in python (subprocess | sys)

2016-05-24 Thread Xristos Xristoou
hello 

i use some programs where support python api. 
but to can use that api from programs need to define some paths(pythonpath 
program and more) and call some batch files(if i not do that i cant access api 
support).create an .bat file where if i run i can use api. 

mybatch.bat 
set ROOT=C:\path\path 
call “%ROOT%“\path1\path1.bat 
call “%ROOT%“\path2\path2\path2\path2\path2.bat 
set GDPATH=%ROOT%\path3\path3 
path %PATH%;”%ROOT%\path4\path4\path4\” 
set PYTHONPATH=%PYTHONPATH%;%ROOT%\path4\path4\path4; 
set PYTHONPATH=%PYTHONPATH%;%ROOT%\path5\path5\path5\path5
set SPATH=%ROOT%\path6 
start “name ide” /B “path from idle.exe” 

but i can use api only from this file i dont want that 

i want to create a script where to run or call batch file with the |subprocess 
| and run on background(activate). 
and i need define path with the |sys|,sys.path.extend,sys.path.append i am not 
sure who is right.
i need a mybatch.bat to convert to python script to take easy api
-- 
https://mail.python.org/mailman/listinfo/python-list


.bat files and path in python(subprocess | sys)

2016-05-24 Thread Xristos Xristoou
hello

i use some programs where support python api.
but to can use that api from programs need to define some paths(pythonpath 
program and more) and call some batch files(if i not do that i cant access api 
support).create an .bat file where if i run i can use api.

mybatch.bat
set ROOT=C:\path\path
call “%ROOT%“\path1\path1.bat
call “%ROOT%“\path2\path2\path2\etc\path2.bat
set GDPATH=%OSGEO4W_ROOT%\path3\path3
path %PATH%;”%OSGEO4W_ROOT%\path\Python27\Scripts\”
set PYTHONPATH=%PYTHONPATH%;%ROOT%\path4\path4\python;
set PYTHONPATH=%PYTHONPATH%;%ROOT%\path5\Python27\Lib\site-packages
set SPATH=%ROOT%\path6
start “name ide” /B “path from idle.exe” 

but i can use api only from this file i dont want that

i want to create a script where to run or call batch file with the |subprocess 
| and run on background(activate).
and i need define path with the |sys|,sys.path.extend,sys.path.append i am not 
sure who is right.

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


Re: for / while else doesn't make sense

2016-05-24 Thread Jon Ribbens
On 2016-05-24, Steven D'Aprano  wrote:
> On Tue, 24 May 2016 08:54 pm, Jon Ribbens wrote:
>> On 2016-05-24, Steven D'Aprano  wrote:
>>> On Tue, 24 May 2016 03:09 am, Jon Ribbens wrote:
 On 2016-05-23, Steven D'Aprano  wrote:
> [...]
>>> In Australia, we have an 11% consumption tax, the GST. I cannot tell you
>>> how many times I've needed to add a 1 cent "Rounding" amount on invoices
>>> to get the results to work out correctly.
>> 
>> Indeed. Using floats for currency calculations is one of the many
>> traps they present, and an excellent example of why their use should
>> not be encouraged.
>
> How do you know the software uses floats?

What software?

> But worse, you ignored my example where I showed that using integer
> arithmetic also generates the same kind of off by one cent errors.

Yes, you showed that you can write broken code. Well done.

>> I very much doubt that you have any such choice - it will usually
>> be specified by the tax regulations.
>
> This is not a matter about the GST legislation. It is a matter of
> mathematics that using integer or fixed point arithmetic is vulnerable to
> the same sorts of rounding errors as floating point arithmetic.

Except it isn't - floats are far more complicated.

>> The correct way to do currency stuff is either integers or Decimal.
>
> You're repeating my words back at me. I already said that.

No, you said the quote that I left in which is still here below:

>>> Using integers in this case is not only *harder* than using floats, but
>>> it's more likely to go wrong. Because integer division always rounds
>>> down, errors accumulate faster than with floats, where calculations will
>>> be correctly rounded to minimize the error.

If that isn't you saying that currency stuff should be done using
floats, then please explain what you did mean, because that's what
it looks like you're saying to me.

>> You are falling into the float trap again. This is not how you do
>> accounting.
>
> Did you look at the code I showed? I'm not using floats. I'm using
> integers, counting in cents.

You didn't say you were using anything. You showed some broken
sample code that you had deliberately written to give the wrong
result, and then said people should use float instead.

> If you're just going to automatically gainsay everything I say
> without even reading what I say first, well, you're no John Cleese.

I did read what you said. Perhaps you should try the same.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: META Culture of this place [was Re: for / while else doesn't make sense]

2016-05-24 Thread Paul Rubin
Ned Batchelder  writes:
> Once the tone gets to picking apart any detail, no matter how trivial, it's
> just turned into a contest to see who can be more right.

It helps to use a threaded news/mail reader (I use gnus).  When a
subtopic starts going off the fails, hitting control-K marks the rest of
the thread as read.  I do that all the time.

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


Re: Strange Python related errors for androwarn.py. Please help!

2016-05-24 Thread Sean Son
Thanks for the reply.

Looks like I am screwed on this one lol

On Tue, May 24, 2016 at 3:31 PM, MRAB  wrote:

> On 2016-05-24 20:04, Sean Son wrote:
>
>> hello all
>>
>> I am testing out a script called androwarn.py, which I downloaded from:
>>
>> https://github.com/mz/androwarn
>>
>> using the instructions found on:
>>
>> https://github.com/mz/androwarn/wiki/Installation
>>
>> When I ran the following commands to test the APK for AirBNB:
>>
>>
>>  python androwarn.py -i SampleApplication/bin/"Airbnb 5.19.0.apk" -v 3 -r
>> html -n
>>
>>
>> I received the following errors:
>>
>> Traceback (most recent call last):
>>   File "androwarn.py", line 116, in 
>> main(options, arguments)
>>   File "androwarn.py", line 99, in main
>> data = perform_analysis(APK_FILE, a, d, x, no_connection)
>>   File "/home/dost/androwarn/androwarn/analysis/analysis.py", line 115, in
>> perform_analysis
>> ( 'device_settings_harvesting',
>> gather_device_settings_harvesting(x) ),
>>   File
>>
>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>> line 96, in gather_device_settings_harvesting
>> result.extend( detect_get_package_info(x) )
>>   File
>>
>> "/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
>> line 79, in detect_get_package_info
>> flags = recover_bitwise_flag_settings(flag,
>> PackageManager_PackageInfo)
>>   File "/home/dost/androwarn/androwarn/util/util.py", line 257, in
>> recover_bitwise_flag_settings
>> if (int(flag) & option_value) == option_value :
>> ValueError: invalid literal for int() with base 10:
>>
>> 'Lcom/google/android/gms/common/GooglePlayServicesUtil;->zzad(Landroid/content/Context;)V'
>>
>>
>> I am absolutely at a loss as to how I should fix these errors? Anyone have
>> any ideas? Sorry for just throwing this at you guys without warning, but
>> Ive been tasked with fixing this at work and I need assistance please!
>>
>> It looks like this issue:
>
> https://github.com/mz/androwarn/issues/10
>
> dating from 11 Dec 2014 and as yet unanswered.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: META Culture of this place [was Re: for / while else doesn't make sense]

2016-05-24 Thread Wildman via Python-list
On Tue, 24 May 2016 10:44:56 -0700, Ned Batchelder wrote:

> On Tuesday, May 24, 2016 at 12:44:04 PM UTC-4, Steven D'Aprano wrote:
>> On Tue, 24 May 2016 12:19 pm, Ned Batchelder wrote:
>> 
>> > Ugh, can we please stop with the "well, actually" pedantic tangents?
>> 
>> With respect, no.
>> 
>> This is a forum with a very tolerant approach to off-topic and only-
>> slightly-on-topic discussions. If you want a forum that follows strict rules
>> for what's allowed and what's not, you're in the wrong place.
> 
> I'm not looking for strict rules.  The discussions can be good.
> 
>> There are
>> plenty of such forums available: Stackoverflow, /r/python, #python,
>> Python-Dev, etc, all with their own idiosyncrasies. This is ours: we have a
>> bunch of people here who enjoy extended discussions on computing matters
>> which are sometimes only tangentially related to Python.
> 
> Can we compromise? Try to cast these discussions in a "yes" form rather 
> than a "no" form?  This very thread got a bit contentious, primarily because
> it seemed like people weren't trying to assume the best about the others in
> the thread.  Having a discussion about the details of floating point is
> fine, but do we want to get into fights over it?  Those can be avoided,
> surely.
> 
> Once the tone gets to picking apart any detail, no matter how trivial, it's
> just turned into a contest to see who can be more right.  When Christopher
> said "8-bit ASCII," he wasn't claiming that ASCII was defined as an 8-bit
> character encoding.  He was making a light-hearted comment about the use
> of esoteric symbols.  You can accept that comment on those terms, rather
> than replying, "No, it's 7-bit."  How many bits ASCII uses is completely
> beside the point.  You don't need to correct people on every tangential
> fact.
> 
> Yes, there are a bunch of people here who enjoy and participate in the
> extended diversions.  But they can also become points of contention, which
> I hope no one wants.  We've seen people vocally not enjoying them. And
> beyond that, harder to gauge is how much they prevent people from entering
> the conversation.
> 
> All I'm asking for is tempering it a bit.  I understand we don't want or
> need strict rules.  But can we stay positive and friendly?
> 
> --Ned.

Although I agree with Steven's comments, I have to agree with what
you said also.  As an amateur programmer, I am constantly learning
new things in this type of discussion and I doubt that I am alone.
However, if/when the discussion falls into name calling and willy
waving, it is time to end the thread.  Just my 2¢.

-- 
 GNU/Linux user #557453
"It's curtains for Windows around my house."
  -Cybe R. Wizard 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange Python related errors for androwarn.py. Please help!

2016-05-24 Thread MRAB

On 2016-05-24 20:04, Sean Son wrote:

hello all

I am testing out a script called androwarn.py, which I downloaded from:

https://github.com/mz/androwarn

using the instructions found on:

https://github.com/mz/androwarn/wiki/Installation

When I ran the following commands to test the APK for AirBNB:


 python androwarn.py -i SampleApplication/bin/"Airbnb 5.19.0.apk" -v 3 -r
html -n


I received the following errors:

Traceback (most recent call last):
  File "androwarn.py", line 116, in 
main(options, arguments)
  File "androwarn.py", line 99, in main
data = perform_analysis(APK_FILE, a, d, x, no_connection)
  File "/home/dost/androwarn/androwarn/analysis/analysis.py", line 115, in
perform_analysis
( 'device_settings_harvesting',
gather_device_settings_harvesting(x) ),
  File
"/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
line 96, in gather_device_settings_harvesting
result.extend( detect_get_package_info(x) )
  File
"/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
line 79, in detect_get_package_info
flags = recover_bitwise_flag_settings(flag, PackageManager_PackageInfo)
  File "/home/dost/androwarn/androwarn/util/util.py", line 257, in
recover_bitwise_flag_settings
if (int(flag) & option_value) == option_value :
ValueError: invalid literal for int() with base 10:
'Lcom/google/android/gms/common/GooglePlayServicesUtil;->zzad(Landroid/content/Context;)V'


I am absolutely at a loss as to how I should fix these errors? Anyone have
any ideas? Sorry for just throwing this at you guys without warning, but
Ive been tasked with fixing this at work and I need assistance please!


It looks like this issue:

https://github.com/mz/androwarn/issues/10

dating from 11 Dec 2014 and as yet unanswered.

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


Strange Python related errors for androwarn.py. Please help!

2016-05-24 Thread Sean Son
hello all

I am testing out a script called androwarn.py, which I downloaded from:

https://github.com/mz/androwarn

using the instructions found on:

https://github.com/mz/androwarn/wiki/Installation

When I ran the following commands to test the APK for AirBNB:


 python androwarn.py -i SampleApplication/bin/"Airbnb 5.19.0.apk" -v 3 -r
html -n


I received the following errors:

Traceback (most recent call last):
  File "androwarn.py", line 116, in 
main(options, arguments)
  File "androwarn.py", line 99, in main
data = perform_analysis(APK_FILE, a, d, x, no_connection)
  File "/home/dost/androwarn/androwarn/analysis/analysis.py", line 115, in
perform_analysis
( 'device_settings_harvesting',
gather_device_settings_harvesting(x) ),
  File
"/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
line 96, in gather_device_settings_harvesting
result.extend( detect_get_package_info(x) )
  File
"/home/dost/androwarn/androwarn/search/malicious_behaviours/device_settings.py",
line 79, in detect_get_package_info
flags = recover_bitwise_flag_settings(flag, PackageManager_PackageInfo)
  File "/home/dost/androwarn/androwarn/util/util.py", line 257, in
recover_bitwise_flag_settings
if (int(flag) & option_value) == option_value :
ValueError: invalid literal for int() with base 10:
'Lcom/google/android/gms/common/GooglePlayServicesUtil;->zzad(Landroid/content/Context;)V'


I am absolutely at a loss as to how I should fix these errors? Anyone have
any ideas? Sorry for just throwing this at you guys without warning, but
Ive been tasked with fixing this at work and I need assistance please!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-05-24 Thread MRAB

On 2016-05-24 18:49, Chris Angelico wrote:

On Wed, May 25, 2016 at 3:44 AM, Steven D'Aprano  wrote:


If you're just going to automatically gainsay everything I say without even
reading what I say first, well, you're no John Cleese.


Yes he is!


He's not John Cleese, he's a very naughty boy. :-)
--
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-05-24 Thread Christopher Reimer
On May 24, 2016, at 7:23 AM, Grant Edwards  wrote:
> 
>> On 2016-05-24, Steven D'Aprano  wrote:
>>> On Tue, 24 May 2016 08:36 am, Christopher Reimer wrote:
>>> 
>>> Those symbols are blowing my 8-bit ASCII brain. :)
>> 
>> That's certainly true, because there is no such thing as 8-bit ASCII.
> 
> He meant to say "my 8-bit, ASCII brain".  The adjectives "8-bit" and
> "ASCII" were both modifying brain.

Nope. I meant 8-bit ASCII (0-255).

http://www.ascii-code.com

Thank you,

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


Re: Unit test a class with xml elements

2016-05-24 Thread John Gordon
In <4c25c98f-9cf0-4a70-b33b-1d2c982de...@googlegroups.com> Palpandi 
 writes:

> Hi,

> How can I unit test a class which using xml elements?
> There is a posiibility of different combinations of xml.

> What is the better way to test this kind of class?
> XML binding is used here.

> Share if any examples available.

Create your own sample XML illustrating each desired combination.

Then write test cases for each.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: ZipImportError: can't find module

2016-05-24 Thread John Gordon
In <1e511b73-e984-459c-9311-77bcd...@googlegroups.com> loial 
 writes:

> What has been working for years suddenly has an error :

> zipimport.ZipImportError: can't find module 'mymodule'

How is the shell script executed?  Is it run interactively, or from a cron
job?

Are the permissions on the zipfile correct, and all parent directories?

How, specifically, are you importing the module?  Are you doing something
like this:

zipfile = zipimport.zipimporter('file.zip')
zipfile.load_module('mymodule')

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: for / while else doesn't make sense

2016-05-24 Thread Pete Forman
Gregory Ewing  writes:

> Pete Forman wrote:
>> However I am coming from scientific measurements where 1.0 is the
>> stored value for observations between 0.95 and 1.05.
>
> You only know that because you're keeping some extra information in
> your head about what the 1.0 stored in your computer represents. It's
> not inherent in the value itself.

No, that is a real case. Floating point hardware can hold intermediate
values in 80 bit registers before writing the double precision result to
8 bytes of memory. There are compiler switches available to enforce
strict IEEE conformance and discard the intermediate guard digits. By
adhering to those rules the results are predictable (repeatable on other
hardware) but less accurate mathematically speaking.

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


Re: Need python script to scan website with safe browsing site status

2016-05-24 Thread mm0fmf

On 24/05/2016 09:05, cheapfiverrservi...@gmail.com wrote:

i need a python script which can scan provided list of websites and scan that 
list with 
https://www.google.com/transparencyreport/safebrowsing/diagnostic/index.html 
and save result of dangerous website or infected website in another text file.



No problem, $2 ($US TWENTY THOUSAND) for a tested program including 
source and 3 months maintenance.


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


Re: for / while else doesn't make sense

2016-05-24 Thread Chris Angelico
On Wed, May 25, 2016 at 3:44 AM, Steven D'Aprano  wrote:
>
> If you're just going to automatically gainsay everything I say without even
> reading what I say first, well, you're no John Cleese.

Yes he is!

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


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Siyi Deng
Here is a summary of what I did with numpy and the dll

I have verified that the values entering the last dll call (dl.cfunction) are 
identical across platforms.


 

The c function has a signature as follows: 

int cfunction(int len_data, float* data, int* ac, int num_ac, 
int flag1, int flag2, int flag3, float* param, 
float* out) 


and in python: 

import numpy as np 
import ctypes as ct 

dl = ct.cdll.LoadLibrary('xxx.dylib')

# data, ac, param are loaded from somewhere else.
data = np.atleast_2d(np.float32(data)) 
ac = np.atleast_2d(np.int32(a)) if a else np.zeros((2, 1), dtype=np.int32) 
param = np.atleast_2d(np.float32(param)) 
flag1 = True
flag2 = True
flag3 = True
num_ac = ac.shape[1] 
len_data = data.shape[1] 
num_inc = len_data//200
out = np.zeros((2, num_inc), dtype=np.float32) 
pt_param = param.ctypes.data_as(cf) if param else None

cf = ct.POINTER(ct.c_float) 
dl.cfunction(len_data, data.ctypes.data_as(cf), 
ac.ctypes.data_as(ct.POINTER(ct.c_int)), 
num_ac, flag1+0, flag2+0, flag3+0, 
pt_param, out.ctypes.data_as(cf)) 


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


Re: META Culture of this place [was Re: for / while else doesn't make sense]

2016-05-24 Thread Ned Batchelder
On Tuesday, May 24, 2016 at 12:44:04 PM UTC-4, Steven D'Aprano wrote:
> On Tue, 24 May 2016 12:19 pm, Ned Batchelder wrote:
> 
> > Ugh, can we please stop with the "well, actually" pedantic tangents?
> 
> With respect, no.
> 
> This is a forum with a very tolerant approach to off-topic and only-
> slightly-on-topic discussions. If you want a forum that follows strict rules
> for what's allowed and what's not, you're in the wrong place.

I'm not looking for strict rules.  The discussions can be good.

> There are
> plenty of such forums available: Stackoverflow, /r/python, #python,
> Python-Dev, etc, all with their own idiosyncrasies. This is ours: we have a
> bunch of people here who enjoy extended discussions on computing matters
> which are sometimes only tangentially related to Python.

Can we compromise? Try to cast these discussions in a "yes" form rather 
than a "no" form?  This very thread got a bit contentious, primarily because
it seemed like people weren't trying to assume the best about the others in
the thread.  Having a discussion about the details of floating point is
fine, but do we want to get into fights over it?  Those can be avoided,
surely.

Once the tone gets to picking apart any detail, no matter how trivial, it's
just turned into a contest to see who can be more right.  When Christopher
said "8-bit ASCII," he wasn't claiming that ASCII was defined as an 8-bit
character encoding.  He was making a light-hearted comment about the use
of esoteric symbols.  You can accept that comment on those terms, rather
than replying, "No, it's 7-bit."  How many bits ASCII uses is completely
beside the point.  You don't need to correct people on every tangential
fact.

Yes, there are a bunch of people here who enjoy and participate in the
extended diversions.  But they can also become points of contention, which
I hope no one wants.  We've seen people vocally not enjoying them. And
beyond that, harder to gauge is how much they prevent people from entering
the conversation.

All I'm asking for is tempering it a bit.  I understand we don't want or
need strict rules.  But can we stay positive and friendly?

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


Re: for / while else doesn't make sense

2016-05-24 Thread Steven D'Aprano
On Tue, 24 May 2016 08:54 pm, Jon Ribbens wrote:

> On 2016-05-24, Steven D'Aprano  wrote:
>> On Tue, 24 May 2016 03:09 am, Jon Ribbens wrote:
>>> On 2016-05-23, Steven D'Aprano  wrote:
[...]
>> In Australia, we have an 11% consumption tax, the GST. I cannot tell you
>> how many times I've needed to add a 1 cent "Rounding" amount on invoices
>> to get the results to work out correctly.
> 
> Indeed. Using floats for currency calculations is one of the many
> traps they present, and an excellent example of why their use should
> not be encouraged.

How do you know the software uses floats?

I haven't told you the name of the accounting software I use. It is
proprietary software, so the source code is unavailable. Unless you work
for the company in question, I doubt you would know what implementation
they use.

But worse, you ignored my example where I showed that using integer
arithmetic also generates the same kind of off by one cent errors.


>> E.g. if an item costs $17 including tax, then you have a choice in
>> rounding the tax-free cost down to $15.31 or up to $15.32,
> 
> I very much doubt that you have any such choice - it will usually
> be specified by the tax regulations.

This is not a matter about the GST legislation. It is a matter of
mathematics that using integer or fixed point arithmetic is vulnerable to
the same sorts of rounding errors as floating point arithmetic.

(Using integers is equivalent to fixed point arithmetic with an implicit
decimal point.)


> The correct way to do currency stuff is either integers or Decimal.

You're repeating my words back at me. I already said that.


>> Using integers in this case is not only *harder* than using floats, but
>> it's more likely to go wrong. Because integer division always rounds
>> down, errors accumulate faster than with floats, where calculations will
>> be correctly rounded to minimize the error.
> 
> You are falling into the float trap again. This is not how you do
> accounting.

Did you look at the code I showed? I'm not using floats. I'm using integers,
counting in cents.

If you're just going to automatically gainsay everything I say without even
reading what I say first, well, you're no John Cleese.



-- 
Steven

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


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Siyi Deng
The c function has a signature as follows:

int cfun(int len_data, float* data, int* a, int num_a,
int flag1, int flag2, int flag3, float* param,
float* out1, float* out2, float* out3)


and in python:

import numpy as np
import ctypes as ct

data = np.atleast_2d(np.float32(data))
a = np.atleast_2d(np.int32(a)) if a else np.zeros((2, 1), dtype=np.int32)
param = np.atleast_2d(np.float32(param))

num_a = activity.shape[1]
len_data = data.shape[1]
num_inc = len_data//256
cf = ct.POINTER(ct.c_float)

hr = np.zeros((2, num_inc), dtype=np.float32)
of = np.zeros((num_inc, 207), dtype=np.float32)
gait = np.zeros((num_inc, 14), dtype=np.float32)
pt_of = of.ctypes.data_as(cf) if do_of else None
pt_gait = gait.ctypes.data_as(cf) if do_gait else None
pt_param = param.ctypes.data_as(cf) if param else None
dl.run_plt_hrm(len_data, data.ctypes.data_as(cf),
activity.ctypes.data_as(ct.POINTER(ct.c_int)),
num_act, do_long_fft+0, do_cls_mitigate+0, do_weighted_average+0,
pt_param, hr.ctypes.data_as(cf), pt_of, pt_gait)

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


Re: Spurious issue in CPython 2.7.5

2016-05-24 Thread Chris Angelico
On Wed, May 25, 2016 at 3:12 AM, Steven D'Aprano  wrote:
>>2: In my process later on I get: "OverflowError: long too big to
>>convert".
>
> Can you copy and paste the actual traceback rather than retyping it from
> memory? I think you're missing something, namely what the long is being
> converted to. The rest of the traceback will help too.
>
>
>>This happens in different places and seems to always relate to
>>obtaining a length of something (dict or list created by list
>>comprehension). Fx
>>
>>"for i in xrange(0, len_of_stuff, max_section_size):"
>>
>>en_of_stuff is always less than the max long (around 600).
>
> What do you mean, "the max long"? Longs do not have a max value. The only
> limit is the amount of memory you have.

A Python long doesn't, but an ssize_t does. In certain places, Python
integers get converted into C integers, at which point an over-large
value triggers OverflowError.

>>> xrange(1<<100)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: Python int too large to convert to C long
>>> xrange(1,500,1<<100)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: Python int too large to convert to C long

(Note: Doesn't happen with a Py3 range object.)

But I echo the request for a copied and pasted error message.

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


Re: META Culture of this place [was Re: for / while else doesn't make sense]

2016-05-24 Thread boB Stepp
On Tue, May 24, 2016 at 11:43 AM, Steven D'Aprano  wrote:

[...]

> ...Python-Dev, etc, all with their own idiosyncrasies. This is ours: we have a
> bunch of people here who enjoy extended discussions on computing matters
> which are sometimes only tangentially related to Python.

I rarely post on this list, but I now diligently read it.  As a person
striving to learn both Python, general C.Sc. topics, good programming
practices, etc., I have found these diversions of great interest, and
like to think I might even have learned some valuable concepts.  If I
would have a quibble, it might be for diversionary posts to be
relabeled in the subject line a bit more diligently, so that one can
still keep track of the original subject matter easily, while still
enjoying the tangential material.  Other than that, I hope that these
sorts of discussions continue unabated!

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


Re: Spurious issue in CPython 2.7.5

2016-05-24 Thread Steven D'Aprano
On Tue, 24 May 2016 08:22 pm, thomas povtal.org wrote:

>Hi,
> 
>Please excuse me if this is not the right place, but I have some issues
>with CPython on a NUMA machine.

Do you mean a Non-Uniform Memory Access machine? 

Can you be more specific about the actual machine and OS used?


>1: I get "RuntimeWarning: tp_compare didn't return -1 or -2 for
>exception". It's a line like:
> 
>"if Foo = False:" where Foo is a global variable (global Foo).

What is the type and value of Foo?


>Now, I've searched somewhat on google for indications on when this
>warning can be seen. However, I haven't really been able to understand
>why and even if it's significant or not. (At face value I'm nervous the
>Python runtime environment is corrupted for that process).

At face value, that RuntimeWarning seems to indicate a bug in the
interpreter.


>2: In my process later on I get: "OverflowError: long too big to
>convert".

Can you copy and paste the actual traceback rather than retyping it from
memory? I think you're missing something, namely what the long is being
converted to. The rest of the traceback will help too.


>This happens in different places and seems to always relate to 
>obtaining a length of something (dict or list created by list
>comprehension). Fx
> 
>"for i in xrange(0, len_of_stuff, max_section_size):"
> 
>en_of_stuff is always less than the max long (around 600).

What do you mean, "the max long"? Longs do not have a max value. The only
limit is the amount of memory you have.

What about max_section_size? How big is that?


>We're using gevent and I'm suspecting some "threading" could cause
>this, as I'm able to replicate it locally with the same data.

Typo: you said later that you are *not* able to replicate it.

You're using a global variable with threaded code? You're a brave (or
foolhardy) man...


-- 
Steven

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


[smtplib] how to assure login was succesful?

2016-05-24 Thread maurice
Hello to all.

I have the following question:

Once my python script reaches the point where I login in my email account with: 
server.login(username,password) (where server server = 
smtplib.SMTP('smtp.office365.com:587')), it returns a tuple like this:

(235,
 '2.7.0 Authentication successful target host [address here]')

This method returns a tuple (code, resp). Just want to confirm if I use a 
variable to store code alone I should check if it is 235 or not, by looking at 
the reference it seems it is the only code value that does not raise an 
exception.

Thank you.


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


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Chris Angelico
On Wed, May 25, 2016 at 2:32 AM, Steven D'Aprano  wrote:
> On Wed, 25 May 2016 02:18 am, Siyi Deng wrote:
>
>> Hello ChrisA,
>> I don't quite understand, the binary shared library contains no python
>> interfaces, it should be independent of python.
>
> In your first post, you said you were using numpy. How is that independent
> of Python?

I'm not certain of the in-memory representation of a numpy array, but
it wouldn't surprise me if it's just a series of consecutive
ints/floats - which would be exactly what a C or Fortran library will
be expecting. So my understanding is that there's some basic ctypes
wrapper code to locate the base address of the array, and then it
passes that straight along.

Of course, without seeing the code

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


META Culture of this place [was Re: for / while else doesn't make sense]

2016-05-24 Thread Steven D'Aprano
On Tue, 24 May 2016 12:19 pm, Ned Batchelder wrote:

> Ugh, can we please stop with the "well, actually" pedantic tangents?

With respect, no.

This is a forum with a very tolerant approach to off-topic and only-
slightly-on-topic discussions. If you want a forum that follows strict rules
for what's allowed and what's not, you're in the wrong place. There are
plenty of such forums available: Stackoverflow, /r/python, #python,
Python-Dev, etc, all with their own idiosyncrasies. This is ours: we have a
bunch of people here who enjoy extended discussions on computing matters
which are sometimes only tangentially related to Python.

And why shouldn't we? We're all volunteers here, including the regulars, and
if it ceases to be fun for us, we'll leave. Some of us *like* those
discussions about the minutia of Unicode, ancient computing platforms,
floating point arithmetic, etc. Sometimes we even learn something.

I'm sorry that you personally don't appreciate these long threads. Maybe you
can mute them in your mail/news editor. Guido often does that on
Python-Ideas. Or just hit delete on posts that don't interest you.

Or perhaps this place simply isn't a good fit for you, just like #python
isn't a good fit for me. I'm not trying to push you away, I really aren't,
and if you decide to leave I will miss your contributions, but this is not
just a forum for Q&A. It's also a forum for (often spirited) discussions
and strongly-held opinions.


-- 
Steven

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


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Steven D'Aprano
On Wed, 25 May 2016 02:18 am, Siyi Deng wrote:

> Hello ChrisA,
> I don't quite understand, the binary shared library contains no python
> interfaces, it should be independent of python. 

In your first post, you said you were using numpy. How is that independent
of Python?

> As a matter of fact, I 
> have successfully used it in Conda python 2.7, 3.5,  Julialang as well as
> c++ executables. I think the fact that only stock python 2.7 failed to run
> correctly indicates some bug in that python distribution.

What do you expect us to say? You still won't show us the code you are
using. Do you expect that we will just take your word for it? If so, then
what? We can't fix this bug (if it is a bug) if we can't identify it.




-- 
Steven

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


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Chris Angelico
On Wed, May 25, 2016 at 2:18 AM, Siyi Deng  wrote:
> I don't quite understand, the binary shared library contains no python 
> interfaces, it should be independent of python. As a matter of fact, I have 
> successfully used it in Conda python 2.7, 3.5,  Julialang as well as c++ 
> executables. I think the fact that only stock python 2.7 failed to run 
> correctly indicates some bug in that python distribution.
>

Ah okay. Still, somehow you have to get the data from the numpy array
to the binary library; and that depends on the exact layout of the
Python object (including pointer sizes and stuff). So your ctypes
interface code might need to be adjusted.

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


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Siyi Deng
Hello ChrisA,
I don't quite understand, the binary shared library contains no python 
interfaces, it should be independent of python. As a matter of fact, I have 
successfully used it in Conda python 2.7, 3.5,  Julialang as well as c++ 
executables. I think the fact that only stock python 2.7 failed to run 
correctly indicates some bug in that python distribution. 


> When you use a binary shared library, it has to be compiled against
> the correct Python. You're messing around with ctypes, so basically
> you've voided your warranty; *everything* you're doing is
> platform-specific. Have fun. :)
> 
> ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Spurious issue in CPython 2.7.5

2016-05-24 Thread thomas povtal.org
   Hi!

   Thanks for the reply.

   Unfortunately I missed a 'not'. I'm not able to reproduce it locally :(

   The corrupted .pyc file experience: I suppose that effect the behaviour
   both if the .pyc file is the main file or as an something that gets
   imported.

   :) T

 Den 24. maj 2016 klokken 15:18 skrev Chris Angelico :

 On Tue, May 24, 2016 at 8:22 PM, thomas povtal.org 
 wrote:
 > Please excuse me if this is not the right place, but I have some
 issues
 > with CPython on a NUMA machine.
 >
 > We're using gevent and I'm suspecting some "threading" could cause
 this,
 > as I'm able to replicate it locally with the same data.

 Perfectly good place to ask. Since you can replicate the problem, can
 you post the code that will trigger this? There are a few
 possibilities. I've once (not "once in a ", once) seen a
 Python installation with corruption in a .pyc file, which resulted in
 really bizarre errors; but more likely, it's something that can be
 shown on multiple systems.

 It's definitely possible that threading can (a) introduce errors, or
 (b) move errors around and make them less obvious. Try to cut your
 example down as much as it can, but it wouldn't surprise me if
 threading remains in it.

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


Re: Spurious issue in CPython 2.7.5

2016-05-24 Thread thomas povtal.org
   Hi!

   Thanks! That was a typo. I do '=='.

   The rest of the mail is ok (with the corrections from Chris)

   :) T

 Den 24. maj 2016 klokken 17:05 skrev Novocastrian_Nomad
 :

 On Tuesday, May 24, 2016 at 5:47:55 AM UTC-6, thomas povtal.org wrote:
 ...
 > 1: I get "RuntimeWarning: tp_compare didn't return -1 or -2 for
 > exception". It's a line like:
 >
 > "if Foo = False:" where Foo is a global variable (global Foo).
 ...

 Are you really using "if Foo = False:"?
 If so, it should be "if Foo == False:"
 "==" for equivalence rather than "=" for assignment.
 --
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Spurious issue in CPython 2.7.5

2016-05-24 Thread Novocastrian_Nomad
On Tuesday, May 24, 2016 at 5:47:55 AM UTC-6, thomas povtal.org wrote:
...
>1: I get "RuntimeWarning: tp_compare didn't return -1 or -2 for
>exception". It's a line like:
> 
>"if Foo = False:" where Foo is a global variable (global Foo).
...

Are you really using "if Foo = False:"?
If so, it should be "if Foo == False:"
"==" for equivalence rather than "=" for assignment.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JNLP File download and run

2016-05-24 Thread Michael Torrie
On 05/24/2016 12:01 AM, Robert Clove wrote:
> Can u provide the pseudo code for the same

I think you'll be disappointed.  What you want to do is a simple,
three-step affair in pseudocode:

download the jnlp file
launch javaws to run the jnlp file
delete jnlp file

That *is* the pseudo code in its entirety.  What more are you expecting?
 Here's a simple, possibly naive, bash example:

#!/bin/bash
jnlp_file=$(mktemp tmpX.jnlp)
wget -O - "$1" > "$jnlp_file"
xdg-open "$jnlp_file"
rm -f "$jnlp_file"

On windows, python ships with a handy wrapper in the os module:
http://stackoverflow.com/questions/15054434/how-can-i-open-files-in-external-programs-in-python
.  With this is in mind, we could expand the pseudocode slightly to work
on multiple platforms:

jnlp_file = create a temporary filename with .jnlp extension
download jnlp_url and write it to jnlp_file

if on windows:
   os.startfile(jnlp_file)
elif on mac:
   execute "open" with the jnlp_file
elif on linux:
   execute "xdg-open" with the jnlp_file

delete  jnlp_file

Take a look at the urls I've found and you'll see how to use urllib and
also subprocess (or os.startfile) to do what you want to do, including
examples you can adapt.  Should be just a few of lines of actual python
code to start with.

> 
> On Fri, May 20, 2016 at 9:06 PM, Michael Torrie  > wrote:
> 
> On 05/20/2016 01:30 AM, Robert Clove wrote:
> > Hi,
> >
> > Can someone give me pseudo code to download and JNLP file from a URL and
> > run it?
> >
> > Looks like a advance concept in python
> 
> You could use the urllib module to download the file, then use the
> subprocess module to spawn the javaws executable and pass it the
> location of the jnlp file as a parameter.
> 
> https://docs.python.org/3.6/howto/urllib2.html
> https://docs.python.org/3.6/library/subprocess.html
> 
> There are other ways besides launching javaws directly, such as asking
> cmd.exe to invoke "start" and the jnlp file so that the default javaws
> executable will run. On Mac there's the "open" binary that can do the
> same thing, and on Linux, xdg-open.
> 
> --
> https://mail.python.org/mailman/listinfo/python-list
> 
> 

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


Re: str(float) python 3 versus 2.7

2016-05-24 Thread Robin Becker

On 23/05/2016 18:05, Ian Kelly wrote:

On Mon, May 23, 2016 at 10:39 AM, Robin Becker  wrote:

.


If you want to show the float in a less noisy format, you can
explicitly format it using the 'g' or 'n' presentation type, which
essentially round to a given precision and strip off trailing zeros:


>>> '{:g}'.format(3*0.2)

'0.6'
thanks; looking in 2.7 source I believe that the old float.__str__ behaved like 
'%.12g' formatting. I can't imagine why people thought this was a 'good' idea 
though.

--
Robin Becker

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


Re: for / while else doesn't make sense

2016-05-24 Thread Grant Edwards
On 2016-05-24, Steven D'Aprano  wrote:
> On Tue, 24 May 2016 08:36 am, Christopher Reimer wrote:
>
>> Those symbols are blowing my 8-bit ASCII brain. :)
>
> That's certainly true, because there is no such thing as 8-bit ASCII.

He meant to say "my 8-bit, ASCII brain".  The adjectives "8-bit" and
"ASCII" were both modifying brain.

-- 
Grant Edwards   grant.b.edwardsYow! I'm pretending that
  at   we're all watching PHIL
  gmail.comSILVERS instead of RICARDO
   MONTALBAN!

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


Re: Spurious issue in CPython 2.7.5

2016-05-24 Thread Chris Angelico
On Tue, May 24, 2016 at 8:22 PM, thomas povtal.org  wrote:
>  Please excuse me if this is not the right place, but I have some issues
>with CPython on a NUMA machine.
>
>We're using gevent and I'm suspecting some "threading" could cause this,
>as I'm able to replicate it locally with the same data.

Perfectly good place to ask. Since you can replicate the problem, can
you post the code that will trigger this? There are a few
possibilities. I've once (not "once in a ", once) seen a
Python installation with corruption in a .pyc file, which resulted in
really bizarre errors; but more likely, it's something that can be
shown on multiple systems.

It's definitely possible that threading can (a) introduce errors, or
(b) move errors around and make them less obvious. Try to cut your
example down as much as it can, but it wouldn't surprise me if
threading remains in it.

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


Unit test a class with xml elements

2016-05-24 Thread Palpandi
Hi,

How can I unit test a class which using xml elements?
There is a posiibility of different combinations of xml.

What is the better way to test this kind of class?
XML binding is used here.

Share if any examples available.


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


Spurious issue in CPython 2.7.5

2016-05-24 Thread thomas povtal.org
   Hi,

   Please excuse me if this is not the right place, but I have some issues
   with CPython on a NUMA machine.

   1: I get "RuntimeWarning: tp_compare didn't return -1 or -2 for
   exception". It's a line like:

   "if Foo = False:" where Foo is a global variable (global Foo).

   Now, I've searched somewhat on google for indications on when this warning
   can be seen. However, I haven't really been able to understand why and
   even if it's significant or not. (At face value I'm nervous the Python
   runtime environment is corrupted for that process).

   2: In my process later on I get: "OverflowError: long too big to convert".
   This happens in different places and seems to always relate to  obtaining
   a length of something (dict or list created by list comprehension). Fx

   "for i in xrange(0, len_of_stuff, max_section_size):"

   en_of_stuff is always less than the max long (around 600).

   We're using gevent and I'm suspecting some "threading" could cause this,
   as I'm able to replicate it locally with the same data.

   Kind regards,

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


Re: for / while else doesn't make sense

2016-05-24 Thread Jon Ribbens
On 2016-05-24, Steven D'Aprano  wrote:
> On Tue, 24 May 2016 03:09 am, Jon Ribbens wrote:
>> On 2016-05-23, Steven D'Aprano  wrote:
>>> But one thing is certain: very few people, Jon Ribbens being one of them,
>>> expects 1/3 to return 0. And that is why Python changed the meaning of
>>> the / operator: because using it for integer division was deeply
>>> unpopular and a bug magnet.
>> 
>> Making it return floats is also a bug magnet, just for more subtle
>> bugs that are harder to diagnose.
>
> Floating point arithmetic does contain traps for the unwary, sometimes very
> subtle ones. But they aren't *bugs* -- they're inherent in the nature of
> floating point arithmetic.

You seem to be repeatedly changing your mind as to which behaviours are
"bugs" and which are not. I didn't say that floating point is buggy
(whatever that would even mean), I said that using it attracts bugs
due to people misunderstanding how it works.

> In Australia, we have an 11% consumption tax, the GST. I cannot tell you how
> many times I've needed to add a 1 cent "Rounding" amount on invoices to get
> the results to work out correctly.

Indeed. Using floats for currency calculations is one of the many
traps they present, and an excellent example of why their use should
not be encouraged.

> E.g. if an item costs $17 including tax, then you have a choice in
> rounding the tax-free cost down to $15.31 or up to $15.32,

I very much doubt that you have any such choice - it will usually
be specified by the tax regulations. The correct way to do currency
stuff is either integers or Decimal.

> Using integers in this case is not only *harder* than using floats, but it's
> more likely to go wrong. Because integer division always rounds down,
> errors accumulate faster than with floats, where calculations will be
> correctly rounded to minimize the error.

You are falling into the float trap again. This is not how you do
accounting.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: RFC: name for project of a cross version disassembler, and unmarshal program

2016-05-24 Thread rocky
On Monday, May 23, 2016 at 2:17:07 AM UTC-4, Pete Forman wrote:
> rocky  writes:
> 
> > I'm looking for a good name for a relatively new project I'll put on pypy.
> >
> > I've been working on a module to disassemble Python bytecode from many
> > versions of Python. (Right now 2.3 .. 3.5 bytecode, largely works.)
> >
> > Of course, in order to do that you also need routines to unmarshal
> > bytecode. So that's in there as well.
> >
> > In the future, I may could add a marshaler and an assembler to Python
> > bytecode. I know, this is kind of perverse.
> >
> > At any rate the name I've been using is "pyxdis". See
> > https://github.com/rocky/python-pyxdis.
> >
> > In the past I've been told by Polish-speaking people that my names are
> > hard to pronounce. (If you've ever heard any Polish tongue twisters,
> > you'll know that this really hurts.)
> >
> > Any suggestions for a better name?
> 
> relipmoc
> 
> -- 
> Pete Forman

I do like the name relipmoc. I'll mention one little thing though. The names of 
the package this will be used in is uncompyle6 which is a variant of 
uncompyle2, uncompyle, decompyle. Those all had the "py" in there and reversing 
throws that off. Or I suppose relypmoc. Or if I want to get the cross-ness in 
there relipmocx or relypmocx. 

Again, I'd be interested in what others think. 

The only other thought I had so far was thinking about was dropping the "py" 
from pyxdis and calling it xdis since it is a cross version "dis" module. But I 
think it is as well a cross-version marshal program and may become a cross 
version assembler too. Does this change anything?
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2016 Keynote: Rachel Willmer

2016-05-24 Thread M.-A. Lemburg
We are pleased to announce our third keynote speaker for EuroPython
2016:

*** Rachel Willmer ***


About Rachel Willmer


Rachel has been working at the "bleeding edge" of technology for 30
years, as programmer, network engineer, manager, startup founder:

   "I remain insatiably curious about how today's new technology gives
   birth to tomorrow's new business opportunity. I am CEO/Founder of
   Luzme, the ebook search site, and a Google Developer Expert
   (Firebase)."


The Keynote: 30 years of Fun & Profit Through Technology


Have you ever wondered how you could be your own boss? or how you
could make money from your side project? or build the next Facebook or
Uber.

To be a coder in today's world of work is to have amazing
opportunities to design the business life you want.


   "I've enjoyed the last 20 years without a 'real job', as company
   founder, freelancer and side-project-hacker.

   Now I am bootstrapping my current company to profitability. Listen
   to my stories and learn from my mistakes and successes."


With gravitational regards,
--
EuroPython 2016 Team
http://ep2016.europython.eu/
http://www.europython-society.org/


PS: Please forward or retweet to help us reach all interested parties:
https://twitter.com/europython/status/735024712061988864
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Need python script to scan website with safe browsing site status

2016-05-24 Thread cheapfiverrservices
i need a python script which can scan provided list of websites and scan that 
list with 
https://www.google.com/transparencyreport/safebrowsing/diagnostic/index.html 
and save result of dangerous website or infected website in another text file.
-- 
https://mail.python.org/mailman/listinfo/python-list


ZipImportError: can't find module

2016-05-24 Thread loial
I am suddenly having a problem with importing a module from a zip file in 
Python 2.4.1

What has been working for years suddenly has an error :

zipimport.ZipImportError: can't find module 'mymodule'

PYTHONPATH is correct, it points to the zip file containing mymodule

N.B. the python script(unchanged) is called from a shell script using

python myscript.py

The python script also has a shebang line that references the 2.4.1 install of 
Python.

Debugging the script shows that PYTHONPATH is set correctly, it points to the 
zip file containing mymodule

Any ideas?

Platform is Solaris 10
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Chris Angelico
On Tue, May 24, 2016 at 5:15 PM, Siyi Deng  wrote:
> Thanks for all the replies.
>
> It turned out that the Apple OS X stock python 2.7 gives the wrong results, 
> but other distributions like 2.7 from miniconda gives the correct results. 
> Facepalm.

When you use a binary shared library, it has to be compiled against
the correct Python. You're messing around with ctypes, so basically
you've voided your warranty; *everything* you're doing is
platform-specific. Have fun. :)

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


Re: Setting Return-Path in email

2016-05-24 Thread dieter
ragav s  writes:
> How can i add different Return-path and fromid in python.i have pasted the 
> below code for preview

Note that there are two different return paths associated with an
email exchange: one on the protocol level (SMPT - RFC821);
the other at the message level.

The one on the protocol level is used for reports about delivery
problems; the one at the message level is used for replies.

You specify the protocol level return path as "from_addr" in your
call to "smpt.sendmail". The message level return path is
usually defined by the "from:" message header and can be overridden
by the "reply-to" message header.

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


Re: Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

2016-05-24 Thread Siyi Deng
Thanks for all the replies.  

It turned out that the Apple OS X stock python 2.7 gives the wrong results, but 
other distributions like 2.7 from miniconda gives the correct results. Facepalm.
-- 
https://mail.python.org/mailman/listinfo/python-list