Re: pypi submission?

2015-04-07 Thread Benjamin Schollnick

> On Apr 6, 2015, at 6:47 PM, Dylan Evans  wrote:
> 
> On 6 April 2015 at 23:21:02, Benjamin Schollnick (bscholln...@gmail.com) 
> wrote:
>> And I’ve been messing around with different config files, etc, trying to 
>> solve the problem  
>> myself.
>> Can anyone point out what I have done wrong?
> 
> What upload command are you using? I see no files at 
> https://pypi.python.org/pypi/Directory_Caching/1.0.5, so pip search returns 
> an entry but there’s nothing to install.  Usually there’s a table with the 
> first heading ‘File’ which contains links to tarballs etc. 
> 
> The command "python setup.py sdist upload” should do it.

That’s what I have been doing…  

I started with using the guide from Peter Downs 
(http://peterdowns.com/posts/first-time-with-pypi.html 
).
That seemed to work fine, until I went to install from pip.  And I’ve been 
hacking at it for about a week or so, with no luck.  I haven’t found any 
troubleshooting guides for pypi.

Here’s the captures of the register, sdist upload, and a verbose pip install 
from pypitest.

My guess is that there is something odd in my setup.py file?  

It’s a merge between several different setup.y’s, I’ve been swapping parts out, 
trying to figure out what is causing it.  But from day 1, using the peter Downs 
setup.py, this problem existed.

Here’s the current version:

"""Directory Caching - A Caching library for Directories & Files

The Directory Caching library caches and manages directory and file listings 
data.
The library is being developed for the (Web) Gallery software.
"""

classifiers = """\
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Programming Language :: Python
Topic :: Database
Topic :: Software Development :: Libraries :: Python Modules
Operating System :: OS Independent
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: Unix
Programming Language :: Python
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
"""
try:
from setuptools import setup, find_packages
except:
from disutils.core import setup, find_packages

__title__ = 'Directory_Caching'
__version__ = '1.10.1'
__author__ = 'Benjamin Schollnick'
__license__ = 'MIT'
__copyright__ = 'Copyright 2015 Benjamin Schollnick'

dependencies = ['natsort', 'scandir']

doclines = __doc__.split("\n")

#
#   Modelled after requests - 
https://github.com/kennethreitz/requests/blob/master/setup.py
#
setup(
name='Directory_Caching',
version=__version__,
description = doclines[0],
long_description = "\n".join(doclines[2:]),
author=__author__,
author_email='benja...@schollnick.net',
url='https://github.com/bschollnick/Directory_Caching',
license="MIT",
maintainer='Benjamin Schollnick',
maintainer_email='benja...@schollnick.net',
packages=find_packages(),
package_dir={'directory_caching': 'directory_caching'},
include_package_data=True,
#platforms=["Any"],
download_url = 
'https://github.com/bschollnick/Directory_Caching/tarball/1.05',
install_requires=dependencies,
keywords = ['caching', 'files', 'directories', 'scandir', 'naturalsort'],
classifiers=filter(None, classifiers.split("\n")),
)


nerv:directory_caching Benjamin$ python setup.py register -r pypitest
running register
running egg_info
writing requirements to Directory_Caching.egg-info/requires.txt
writing Directory_Caching.egg-info/PKG-INFO
writing top-level names to Directory_Caching.egg-info/top_level.txt
writing dependency_links to Directory_Caching.egg-info/dependency_links.txt
reading manifest file 'Directory_Caching.egg-info/SOURCES.txt'
writing manifest file 'Directory_Caching.egg-info/SOURCES.txt'
running check
Registering Directory_Caching to https://testpypi.python.org/pypi
Server response (200): OK


nerv:directory_caching Benjamin$ python setup.py sdist upload -r pypitest
running sdist
running egg_info
writing requirements to Directory_Caching.egg-info/requires.txt
writing Directory_Caching.egg-info/PKG-INFO
writing top-level names to Directory_Caching.egg-info/top_level.txt
writing dependency_links to Directory_Caching.egg-info/dependency_links.txt
reading manifest file 'Directory_Caching.egg-info/SOURCES.txt'
writing manifest file 'Directory_Caching.egg-info/SOURCES.txt'
warning: sdist: standard file not found: should have one of README, 
README.rst, README.txt

running check
creating Directory_Caching-1.10.1
creating Directory_Caching-1.10.1/Directory_Caching.egg-info
creating Directory_Caching-1.10.1/directory_caching
making hard links in Directory_Caching-1.10.1...
hard linking setup.cfg -> Directory_Caching-1.10.1
hard linking setup.py -> Directory_Caching-1.10.1
hard linking Directory_Caching.egg-info/PKG-INFO -> 
Directory_Caching-1.10.1/Directory_Ca

Trying to hire or grow a Python developer for a 2 year contract

2015-04-07 Thread Peter Rowley
 

Hi, 

I'm at York University in Toronto, Canada. We have a large
Python-and-Oracle web application written with Pyramids and YUI that we
use to manage the staffing of courses at York and are looking for an
intermediate or senior developer for a 2 year contract to work on
extensions to the application. If you are interested or know of someone
who would be, please e-mail me at prow...@yorku.ca. The salary is
approximately $75,000 a year and benefits are excellent. 

We have been looking for someone for this position for a while and are
starting to think about hiring someone who has good programming skills
but not necessarily Python. To that end, if you're a Python developer or
hire them, I'd be interested in your opinion of which common programming
languages that people might know would enable learning Python? I'm
guessing PHP for the dynamic language concepts and Java for the
structure, but that's not based on much evidence. 

Thanks in advance 

Peter Rowley, Director of Applications and Integration 

University Information Technology, York University, Toronto 

prow...@yorku.ca 

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


Russell--Those additional questions you had

2015-04-07 Thread John Kelly
Pythonites,
I received Python with another install and my update software keeps signaling I 
need to install a newer version, and once I do, the older version is still 
there, so I keep getting told I need to update. Should I be able to uninstall 
the old version each time?
Thanks for your kind attention,John Kelly
On 3/31/15 10:09 AM, John Kelly wrote:
> Pythonites,
>
> I received Python with another install and my update software keeps
> signaling I need to install a newer version, and once I do, the older
> version is still there, so I keep getting told I need to update. Should
> I be able to uninstall the old version each time?
>
> Thanks for your kind attention,
> John Kelly

I would need more information to help. What operating system are you on? 
How and where are you installing Python (and what do you mean by 
"received Python with another install"?).

-- Russell
Russell,
I found Python on my system through the use of Secunia PSI, as it was flagged 
as needing update and I had not noticed Python before.  

It shows Python 2.5.X in C:\Program Files (x86)\Acer\clear.fi 
SDK21\Video\koan\python25.dll and shows Python 2.7.X in 
C:\Windows\SysWOW64\python27.dll and shows Python 2.7.x in 
C:\Windows\System32\Python27.dll and also Python 3.x in 
C:\Windows\SysWOW64\Python34.dll
I just wonder if all these copies are necessary or if I am supposed to manually 
uninstall the previous versions.  When I download an upgrade, I love to see the 
installer removing old files before installing the upgrade, and feel almost 
sure it's dumping almost all the effluent of old versions.  

Secunia sometimes gets a wild hair in its program to keep all installs up to 
date, and  will flag something it claims to be updating but never seems to 
accomplish this, so must be done manually.  Fair enough, as it was free and 
only trying to help secure my system.  Here are the stats on my system:
OS Name    Microsoft Windows 7 Home Premium
Version    6.1.7601 Service Pack 1 Build 7601
Other OS Description     Not Available
OS Manufacturer    Microsoft Corporation
System Manufacturer    Acer
System Model    Predator G3620
System Type    x64-based PC
Processor    Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz, 3401 Mhz, 4 Core(s), 8 
Logical Processor(s)
BIOS Version/Date    American Megatrends Inc. P01-A1, 3/12/2012
SMBIOS Version    2.7
Windows Directory    C:\Windows
System Directory    C:\Windows\system32
Boot Device    \Device\HarddiskVolume2
Locale    United States
Hardware Abstraction Layer    Version = "6.1.7601.17514"
Time Zone    Eastern Daylight Time
Installed Physical Memory (RAM)    12.0 GB
Total Physical Memory    11.9 GB
Available Physical Memory    9.00 GB
Total Virtual Memory    23.9 GB
Available Virtual Memory    20.7 GB
Page File Space    11.9 GB
Page File    C:\pagefile.sys

I appreciate your offer of help and hope to not need to interrupt your time 
further.  I am intrigued, however, by this computing language being made more 
understandable for a neophyte like myself.  I'll read a bit more about 
it.Thanks!John Kelly
-- 
https://mail.python.org/mailman/listinfo/python-list


Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall


I want todo faster baseconversion for very big bases like base 1 000 000, so 
instead of adding up digits i search it. 

I need the fastest algorithm to find the relation to a decimal number. 
Digmult is an instance of base at a digitplace (base^x) what i try to find is 
the digit for the below condition is true and the loop break. 


* 
for (digit=0;digit<=base;digit++) { 
   if((digit+1)*digmult>decNumber)break; 
} 
* 

So i am looking for the digit where following condition true. 

if((digit)*digmultdecNumber) then BREAK; 

One could start at half base searching, but then i Think i've read that using 
1/3 closing in faster? 

I Think also i remember that if the search space so big that at least 22 or 23 
guesses, needed.A random Oracle may even faster? 

Just pick up a number and get lucky, is it any truth to that? 

Below the actual algorithm. 



 
//CONVERT A DECIMAL NUMBER INTO ANYBASE 
function newbase(decNumber,base){ 
digits=1; 
digmult=1; 
while(digmult*base<=decNumber){ 
digmult=digmult*base 
digits++; 
} 
digsave=digmult; 
while(decNumber>0 || digits>0){ 
loop=1; 
digit=0; 
   for (digit=0;digit<=base;digit++) { 
if((digit+1)*digmult>decNumber)break; 
   } 
out[digits]=digit; 
digmult=digmult*digit; 
decNumber=decNumber-digmult; 
digsave=digsave/base; 
digmult=digsave; 
digits--; 
} 
return out; 
} 

var out= []; 
base=256; 
number=854544; 
out=newbase(number,base); 
out.reverse(); 
document.write("Number = ",out,"
"); -- https://mail.python.org/mailman/listinfo/python-list

Re: Help with pipes, buffering and pseudoterminals

2015-04-07 Thread Chris Angelico
On Tue, Apr 7, 2015 at 3:48 PM, Cameron Simpson  wrote:
> The operating system arranges the commection of the shell to the terminal.
> Your usual program has by default a stdin, stdout and stderr. These are
> _all_ the same file handle, duplicated to each of the three file descriptors
> 0, 1 and 2 respectively. On the operating system side, the OS has performed
> _one_ open() call on the terminal device and handed the caller a single file
> descriptor. The caller then calls dup() (or modernly, dup2()) to present the
> open terminal as stdin, stdout and stderr.

Really? I can believe that stdout and stderr are initially duplicates,
but stdin as well? Isn't stdin opened for reading only, and
stdout/stderr for writing only?

I grew up on DOS and OS/2, not on Unix, so maybe there's a massive
simplification here that I'm not aware of. That'd be pretty clean and
tidy if what you say is the case!

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


Re: Trying to hire or grow a Python developer for a 2 year contract

2015-04-07 Thread felix

El 05/04/15 13:28, Peter Rowley escribió:


 Hi,

I'm at York University in Toronto, Canada.  We have a large 
Python-and-Oracle web application written with Pyramids and YUI that 
we use to manage the staffing of courses at York and are looking for 
an intermediate or senior developer for a 2 year contract to work on 
extensions to the application.  If you are interested or know of 
someone who would be, please e-mail me at prow...@yorku.ca.  The 
salary is approximately $75,000 a year and benefits are excellent.


We have been looking for someone for this position for a while and are 
starting to think about hiring someone who has good programming skills 
but not necessarily Python.  To that end, if you're a Python developer 
or hire them, I'd be interested in your opinion of which common 
programming languages that people might know would enable learning 
Python?  I'm guessing PHP for the dynamic language concepts and Java 
for the structure, but that's not based on much evidence.



Nice job!
It makes me realize that studying Python is not just fun but also an 
opportunity to get paid!
Bad for me because I'm just a beginner. I started with Python and Django 
a year ago! ;)


I read the basic concepts of several languages when I was a student: 
Basic, Pascal, C, Assembly language for x86 processor, then some basic 
concepts of OOP, then PHP and I found Python is so natural and easy to 
start with as they say in tutorials.


I'm sure you will find someone soon, Mr. Rowley.
Good luck!!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Dave Angel

On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:



I want todo faster baseconversion for very big bases like base 1 000 000, so 
instead of adding up digits i search it.


For this and most of the following statements:  I can almost guess what 
you're trying to say.  However, I cannot.  No idea why you're adding up 
digits, that sounds like casting out nines.  And in base-N, that would 
be casting out (N-1)'s.


What's the it you're trying to search?

How do you know the baseconversion is the bottleneck, if you haven't 
written any Python code yet?





I need the fastest algorithm to find the relation to a decimal number.


What relation would that be?  Between what and what?


Digmult is an instance of base at a digitplace (base^x) what i try to find is 
the digit for the below condition is true and the loop break.



You haven't defined a class "Base" yet.  In fact, I don't see any Python 
code in the whole message.




*
for (digit=0;digit<=base;digit++) {
if((digit+1)*digmult>decNumber)break;
}
*





So i am looking for the digit where following condition true.

if((digit)*digmultdecNumber) then BREAK;


You could try integer divide.  That's just something like
 digit = decNumber // digmult
But if you think hard enough you'd realize that




One could start at half base searching, but then i Think i've read that using 
1/3 closing in faster?

I Think also i remember that if the search space so big that at least 22 or 23 
guesses, needed.A random Oracle may even faster?

Just pick up a number and get lucky, is it any truth to that?

Below the actual algorithm.




//CONVERT A DECIMAL NUMBER INTO ANYBASE
function newbase(decNumber,base){
digits=1;
digmult=1;
while(digmult*base<=decNumber){
 digmult=digmult*base
 digits++;
}
digsave=digmult;
while(decNumber>0 || digits>0){
 loop=1;
 digit=0;
for (digit=0;digit<=base;digit++) {
 if((digit+1)*digmult>decNumber)break;
}
 out[digits]=digit;
 digmult=digmult*digit;
 decNumber=decNumber-digmult;
 digsave=digsave/base;
 digmult=digsave;
 digits--;
 }
return out;
}

var out= [];
base=256;
number=854544;
out=newbase(number,base);
out.reverse();
document.write("Number = ",out,"
"); If that code were in Python, I could be more motivated to critique it. The whole algorithm could be much simpler. But perhaps there is some limitation of javascript that's crippling the code. How would you do it if you were converting the base by hand? I certainly wouldn't be doing any trial and error. For each pass, I'd calculate quotient and remainder, where remainder is the digit, and quotient is the next value you work on. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list

Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 15:30:36 UTC+2 skrev Dave Angel:
> On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:
> >
> >
> > I want todo faster baseconversion for very big bases like base 1 000 000, 
> > so instead of adding up digits i search it.
> 
> For this and most of the following statements:  I can almost guess what 
> you're trying to say.  However, I cannot.  No idea why you're adding up 
> digits, that sounds like casting out nines.  And in base-N, that would 
> be casting out (N-1)'s.
> 
> What's the it you're trying to search?
> 
> How do you know the baseconversion is the bottleneck, if you haven't 
> written any Python code yet?
> 
> 
> >
> > I need the fastest algorithm to find the relation to a decimal number.
> 
> What relation would that be?  Between what and what?
> 
> > Digmult is an instance of base at a digitplace (base^x) what i try to find 
> > is the digit for the below condition is true and the loop break.
> >
> 
> You haven't defined a class "Base" yet.  In fact, I don't see any Python 
> code in the whole message.
> 
> >
> > *
> > for (digit=0;digit<=base;digit++) {
> > if((digit+1)*digmult>decNumber)break;
> > }
> > *
> 
> 
> >
> > So i am looking for the digit where following condition true.
> >
> > if((digit)*digmultdecNumber) then 
> > BREAK;
> 
> You could try integer divide.  That's just something like
>   digit = decNumber // digmult
> But if you think hard enough you'd realize that
> 
> 
> >
> > One could start at half base searching, but then i Think i've read that 
> > using 1/3 closing in faster?
> >
> > I Think also i remember that if the search space so big that at least 22 or 
> > 23 guesses, needed.A random Oracle may even faster?
> >
> > Just pick up a number and get lucky, is it any truth to that?
> >
> > Below the actual algorithm.
> >
> >
> >
> > 
> > //CONVERT A DECIMAL NUMBER INTO ANYBASE
> > function newbase(decNumber,base){
> > digits=1;
> > digmult=1;
> > while(digmult*base<=decNumber){
> >  digmult=digmult*base
> >  digits++;
> > }
> > digsave=digmult;
> > while(decNumber>0 || digits>0){
> >  loop=1;
> >  digit=0;
> > for (digit=0;digit<=base;digit++) {
> >  if((digit+1)*digmult>decNumber)break;
> > }
> >  out[digits]=digit;
> >  digmult=digmult*digit;
> >  decNumber=decNumber-digmult;
> >  digsave=digsave/base;
> >  digmult=digsave;
> >  digits--;
> >  }
> > return out;
> > }
> >
> > var out= [];
> > base=256;
> > number=854544;
> > out=newbase(number,base);
> > out.reverse();
> > document.write("Number = ",out,"
"); > > > > > > If that code were in Python, I could be more motivated to critique it. > The whole algorithm could be much simpler. But perhaps there is some > limitation of javascript that's crippling the code. > > How would you do it if you were converting the base by hand? I > certainly wouldn't be doing any trial and error. For each pass, I'd > calculate quotient and remainder, where remainder is the digit, and > quotient is the next value you work on. > > > -- > DaveA I am doing it just like i would do it by hand finding the biggest digit first. To do that i need to know nearest base^exp that is less than the actual number. Add up the digit (multiply) it to the nearest smaller multiple. Subtract that number (base^exp*multiple). Divide / Scale down the exponent with base. And record the digit. And start looking for next digit doing same manipulation until remainder = 0. And that is what i am doing. -- https://mail.python.org/mailman/listinfo/python-list

Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-07 Thread Khyati
Thanks for taking a look, Chris.
The error trace:
traceback (most recent call last):
 File "MonitorRegistry.py", line 18, in 
   process_created = watcher()
 File "C:\Python27\lib\site-packages\wmi.py", line 1195, in __call__
   handle_com_error ()
 File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
   raise klass (com_error=err)
_wmi: 

when I debugged this is the module that throws the exception:
wmi.py [Line 1178-1195]
 def __call__ (self, timeout_ms=-1):
"""When called, return the instance which caused the event. Supports
 timeout in milliseconds (defaulting to infinite). If the watcher
 times out, :exc:`x_wmi_timed_out` is raised. This makes it easy to support
 watching for multiple objects.
"""
try:
  event = self.wmi_event.NextEvent (timeout_ms)
  if self.is_extrinsic:
return _wmi_event (event, None, self.fields)
  else:
return _wmi_event (
  event.Properties_ ("TargetInstance").Value,
  _wmi_object (event, property_map=self._event_property_map),
  self.fields
)
except pywintypes.com_error:
  handle_com_error ()

self.is_extrinsic returns false and event.Properties_("TargetInstance").Value 
throws the exception

Here is the entire(minimal) code:
import wmi
import _winreg
c = wmi.WMI ()
raw_wql = "SELECT * FROM RegistryValueChangeEvent WHERE 
Hive='HKEY_LOCAL_MACHINE' AND KeyPath='SoftwareTemp' AND ValueName='Name'"
print raw_wql
watcher = c.watch_for(raw_wql=raw_wql,wmi_class = "__ExtrinsicEvent")
while True:
  try:
process_created = watcher()
print 'value changed'


I have already emailed - Tim Golden 
Any other group that I can reach to?


Thanks
Khyati

On Monday, April 6, 2015 at 7:50:37 PM UTC-4, Chris Angelico wrote:
> On Tue, Apr 7, 2015 at 8:02 AM, Khyati  wrote:
> > I have a question about RegistryValueChangeEvent that I have not been able 
> > to find an answer to on the internet so far. I would appreciate any help 
> > since I have already spent a lot of time finding any material that explains 
> > this:
> >
> > What I am trying to do:
> > - create an event when a value for a registry key changes
> 
> Thanks for being clear about this part! Unfortunately, there are a few
> other parts that aren't clear yet, so hopefully you can expand on your
> question a bit.
> 
> > How I am doing it:
> >>raw_wql = "SELECT * FROM RegistryValueChangeEvent WHERE 
> >>Hive='HKEY_LOCAL_MACHINE' AND KeyPath='SoftwareTemp' AND 
> >>ValueName='Name\'"
> 
> Tip: Try adding "print(raw_wql)" just underneath this line, to see if
> you're getting back what you really want. The backslash at the end of
> ValueName is not currently doing anything.
> 
> >>watcher = c.watch_for(raw_wql=raw_wql,wmi_class = "__ExtrinsicEvent")
> >>while TRUE:
> >>process_created = watcher()
> 
> This code isn't complete. Can you post a complete (and minimal)
> example piece of code?
> 
> > Problem:
> > the _wmi_event object returned is not coming back as Extrinsic event -
> > So, in wmi.py, in class _wmi_watcher:
> >"self.is_extrinsic" returns false and I get an exception from the else 
> > part - [line 1186 - 1195]
> 
> It'd help hugely if you could post the entire traceback here - what
> exception you're getting, and the exact lines that produce it.
> 
> > What I need
> > - Any reference/idea/explanation on => why does RegistryValueChangeEvent 
> > returns as a Non-Extrinsic  event? even though it has been derived from 
> > __ExtrinsicEvent
> >
> > Other information:
> > Running on Windows 8 64 Bit
>  platform.machine()
> > 'AMD64'
>  platform.architecture()
> > ('64bit', 'WindowsPE')
>  platform.python_version()
> > '2.7.8'
>  platform.python_implementation()
> > 'CPython'
> >
> > Using WMI-1.4.9.win32 - downloaded via PIP
> > pywin32-219.win-amd64-py2.7
> 
> Just for reference, this is a general Python discussion list. Lots of
> us won't know specific libraries, so all we can offer is fairly
> general information. If you can't get the help you need here, you may
> do better to look for more specific help about this module.
> 
> All the best!
> 
> ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Dave Angel

On 04/07/2015 10:10 AM, jonas.thornv...@gmail.com wrote:

Den tisdag 7 april 2015 kl. 15:30:36 UTC+2 skrev Dave Angel:


   


If that code were in Python, I could be more motivated to critique it.
The whole algorithm could be much simpler.  But perhaps there is some
limitation of javascript that's crippling the code.

How would you do it if you were converting the base by hand?  I
certainly wouldn't be doing any trial and error.  For each pass, I'd
calculate quotient and remainder, where remainder is the digit, and
quotient is the next value you work on.


--
DaveA


I am doing it just like i would do it by hand finding the biggest digit first. 
To do that i need to know nearest base^exp that is less than the actual number. 
Add up the digit (multiply) it to the nearest smaller multiple. Subtract that 
number (base^exp*multiple).

Divide / Scale down the exponent with base. And record the digit.
And start looking for next digit doing same manipulation until remainder = 0.

And that is what i am doing.



Then I don't know why you do the call to reverse() in the top-level code.

If I were doing it, I'd have no trial and error in the code at all. 
Generate the digits right to left, then reverse them before returning.


For example, if you want to convert 378 to base 10 (it's binary 
internally), you'd divide by 10 to get 37, remainder 8.  Save the 8, and 
loop again.  Divide 37 by 10 and get 3, remainder 7.  Save the 7. Divide 
again by 10 and get 0, remainder 3.  Save the 3


Now you have '8', '7', '3'   So you reverse the list, and get
 '3', '7', '8'



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


Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-07 Thread Chris Angelico
On Wed, Apr 8, 2015 at 12:15 AM, Khyati  wrote:
> Thanks for taking a look, Chris.
> The error trace:
> traceback (most recent call last):
>  File "MonitorRegistry.py", line 18, in 
>process_created = watcher()
>  File "C:\Python27\lib\site-packages\wmi.py", line 1195, in __call__
>handle_com_error ()
>  File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
>raise klass (com_error=err)
> _wmi:  u'SWbemPropertySet', u'Not found ', None, 0, -2147217406), None)>

It looks to me like this is a thin wrapper around the underlying API
call, and you're getting back an error from the lower-level services.
The way this reads, there might well not be an
HKLM\Software\Temp\Name; maybe the ValueName is what's wrong here?

Someone somewhere knows more than I do, but if you can't find that
someone here on python-list, you might be able to find some help on
Stack Overflow or another mailing list, from people who know how to do
this kind of thing in a different language. You'd have to translate
their suggestions back into Python, but when the wrappers are thin
enough, that's usually not too hard.

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 3:44 AM,   wrote:
>
>
> I want todo faster baseconversion for very big bases like base 1 000 000, so 
> instead of adding up digits i search it.
>
> I need the fastest algorithm to find the relation to a decimal number.
> Digmult is an instance of base at a digitplace (base^x) what i try to find is 
> the digit for the below condition is true and the loop break.
>
>
> *
> for (digit=0;digit<=base;digit++) {
>if((digit+1)*digmult>decNumber)break;
> }
> *
>
> So i am looking for the digit where following condition true.
>
> if((digit)*digmultdecNumber) then BREAK;

I'm not sure that I understand what it is that you're trying to
accomplish. Are you trying to find the digits without using division
because "division is slow"? If that's the case, then let me show you
something.

$ python -m timeit -s "n = 1523837293" "n // 100"
100 loops, best of 3: 0.286 usec per loop

$ python -m timeit -s "n = 1523" "n * 100; (n+1) * 100"
100 loops, best of 3: 0.455 usec per loop

In Python, one addition and two multiplications are already slower
than a single division. The only way you're going to beat division by
using trial multiplication is if the first digit that you try is
always correct. To do that, you would need an oracle feeding your
search algorithm, and then you might as well just use the oracle.

> One could start at half base searching, but then i Think i've read that using 
> 1/3 closing in faster?

Do you mean binary search? That would be an improvement over the
linear search algorithm you've shown. Whether a trinary search might
be faster would depend on the distribution of the numbers you expect.
If they're evenly distributed, it will be slower.

> I Think also i remember that if the search space so big that at least 22 or 
> 23 guesses, needed.A random Oracle may even faster?
>
> Just pick up a number and get lucky, is it any truth to that?

On average, a random Oracle with a search space of 100 will need
100 guesses.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Chris Angelico
On Wed, Apr 8, 2015 at 12:26 AM, Dave Angel  wrote:
> For example, if you want to convert 378 to base 10 (it's binary internally),
> you'd divide by 10 to get 37, remainder 8.  Save the 8, and loop again.
> Divide 37 by 10 and get 3, remainder 7.  Save the 7. Divide again by 10 and
> get 0, remainder 3.  Save the 3
>
> Now you have '8', '7', '3'   So you reverse the list, and get
>  '3', '7', '8'

Technically, it doesn't matter that it's stored in binary. All that
matters is that it's stored in some way that you can perform division
on. I used to do this kind of thing in assembly language, pushing
digits onto the stack, then popping them off afterward. (It's actually
easier to make a column of numbers right-justified, as you can simply
create a buffer of the right size - assuming you're working with a
machine word and can know the maximum size - and populate it from the
far end.) But yes, this is the standard way to do base conversions.

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Denis McMahon
On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote:

> On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:

>> I want todo faster baseconversion for very big bases like base 1 000
>> 000, so instead of adding up digits i search it.

> How do you know the baseconversion is the bottleneck, if you haven't
> written any Python code yet?

He doesn't. He doesn't comprehend that as far as a computer is concerned 
an integer has no specific 'base', it's only when presented in a form for 
humans to read that it gets base information added in the representation.

He's making these and other similar errors in the javascript groups too.

I suspect he's one of those people that spends his time thinking up 
elaborate solutions that he has no idea how to implement as a response to 
dreamt up non existent problems.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 16:30:15 UTC+2 skrev Denis McMahon:
> On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote:
> 
> > On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:
> 
> >> I want todo faster baseconversion for very big bases like base 1 000
> >> 000, so instead of adding up digits i search it.
> 
> > How do you know the baseconversion is the bottleneck, if you haven't
> > written any Python code yet?
> 
> He doesn't. He doesn't comprehend that as far as a computer is concerned 
> an integer has no specific 'base', it's only when presented in a form for 
> humans to read that it gets base information added in the representation.
> 
> He's making these and other similar errors in the javascript groups too.
> 
> I suspect he's one of those people that spends his time thinking up 
> elaborate solutions that he has no idea how to implement as a response to 
> dreamt up non existent problems.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com

Bullshit declare two integers in any language one 7 and one 4 and then write 
x=7+4; if you find a programming language where that does not yield 11 tell me.

Integers are internally assumed to be base 10 otherwise you could not calculate 
without giving the base.

All operations on integers addition, subtraction, multiplication and division 
assume base 10.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-07 Thread Khyati
On Tuesday, April 7, 2015 at 10:31:47 AM UTC-4, Chris Angelico wrote:
> On Wed, Apr 8, 2015 at 12:15 AM, Khyati wrote:
> > Thanks for taking a look, Chris.
> > The error trace:
> > traceback (most recent call last):
> >  File "MonitorRegistry.py", line 18, in 
> >process_created = watcher()
> >  File "C:\Python27\lib\site-packages\wmi.py", line 1195, in __call__
> >handle_com_error ()
> >  File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
> >raise klass (com_error=err)
> > _wmi:  > u'SWbemPropertySet', u'Not found ', None, 0, -2147217406), None)>
> 
> It looks to me like this is a thin wrapper around the underlying API
> call, and you're getting back an error from the lower-level services.
> The way this reads, there might well not be an
> HKLM\Software\Temp\Name; maybe the ValueName is what's wrong here?
> 
> Someone somewhere knows more than I do, but if you can't find that
> someone here on python-list, you might be able to find some help on
> Stack Overflow or another mailing list, from people who know how to do
> this kind of thing in a different language. You'd have to translate
> their suggestions back into Python, but when the wrappers are thin
> enough, that's usually not too hard.
> 
> ChrisA

HKLM\Software\Temp\Name exists since the event is caught correctly only when I 
change that key.
i'll keep looking :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Chris Angelico
On Wed, Apr 8, 2015 at 12:36 AM,   wrote:
> Bullshit declare two integers in any language one 7 and one 4 and then write 
> x=7+4; if you find a programming language where that does not yield 11 tell 
> me.
>
> Integers are internally assumed to be base 10 otherwise you could not 
> calculate without giving the base.
>
> All operations on integers addition, subtraction, multiplication and division 
> assume base 10.

You misunderstand how computers and programming languages work. What
you're seeing there is that *integer literals* are usually in base 10;
and actually, I can point to plenty of assembly languages where the
default isn't base 10 (it's usually base 16 (hexadecimal) on IBM PCs,
and probably base 8 (octal) on big iron). This is nothing to do with
the internal representation, and all to do with source code.

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


Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-07 Thread Tim Golden
On 07/04/2015 15:35, Khyati wrote:
> On Tuesday, April 7, 2015 at 10:31:47 AM UTC-4, Chris Angelico wrote:
>> On Wed, Apr 8, 2015 at 12:15 AM, Khyati wrote:
>>> Thanks for taking a look, Chris.
>>> The error trace:
>>> traceback (most recent call last):
>>>  File "MonitorRegistry.py", line 18, in 
>>>process_created = watcher()
>>>  File "C:\Python27\lib\site-packages\wmi.py", line 1195, in __call__
>>>handle_com_error ()
>>>  File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
>>>raise klass (com_error=err)
>>> _wmi: >> u'SWbemPropertySet', u'Not found ', None, 0, -2147217406), None)>
>>
>> It looks to me like this is a thin wrapper around the underlying API
>> call, and you're getting back an error from the lower-level services.
>> The way this reads, there might well not be an
>> HKLM\Software\Temp\Name; maybe the ValueName is what's wrong here?
>>
>> Someone somewhere knows more than I do, but if you can't find that
>> someone here on python-list, you might be able to find some help on
>> Stack Overflow or another mailing list, from people who know how to do
>> this kind of thing in a different language. You'd have to translate
>> their suggestions back into Python, but when the wrappers are thin
>> enough, that's usually not too hard.
>>
>> ChrisA
> 
> HKLM\Software\Temp\Name exists since the event is caught correctly only when 
> I change that key.
> i'll keep looking :)
> 

Hi, Khyati.

Unfortunately, extrinsic events don't come with much information. As you
can see from the MSDN description:

https://msdn.microsoft.com/en-us/library/aa390355%28v=vs.85%29.aspx

they're not linked to WMI objects internally (which the intrinsic events
are) so all they can do is echo back to you details of what changed --
which will usually be the thing you were asking about in the first place!

So the Python wrapper doesn't receive any TargetInstance because it's
not a *WMI* event as such, linked to a WMI object; rather, it's an
external event which has provided a hook for WMI to hang on to.

In this specific case, you could use the WMI Registry provider to pick
up the current value of that registry value, but that wouldn't tell you
what was there before or anything else. In another case, the event might
be about some entirely external system -- such as the
SecurityViolationEvent in the MSDN example -- which provides no WMI
interface beyond the event itself.

Feel free to ask more, either on this list or on the win32-specific
Python list:

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

(I'm not often free to answer questions so best to use the public forums
where more people will be able to help).

TJG


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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread MRAB

On 2015-04-07 15:36, jonas.thornv...@gmail.com wrote:

Den tisdag 7 april 2015 kl. 16:30:15 UTC+2 skrev Denis McMahon:

On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote:


On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:



I want todo faster baseconversion for very big bases like base
1 000 000, so instead of adding up digits i search it.



How do you know the baseconversion is the bottleneck, if you
haven't written any Python code yet?


He doesn't. He doesn't comprehend that as far as a computer is
concerned an integer has no specific 'base', it's only when
presented in a form for humans to read that it gets base
information added in the representation.

He's making these and other similar errors in the javascript groups
too.

I suspect he's one of those people that spends his time thinking
up elaborate solutions that he has no idea how to implement as a
response to dreamt up non existent problems.


Bullshit declare two integers in any language one 7 and one 4 and
then write x=7+4; if you find a programming language where that does
not yield 11 tell me.

Integers are internally assumed to be base 10 otherwise you could not
calculate without giving the base.

All operations on integers addition, subtraction, multiplication and
division assume base 10.


Sorry to say this, but that's nonsense.

It doesn't matter what base it's working in internally; usually it's
base 2 (binary), because that's simpler to implement.

It's only when you're converting from or to text that you need specify
a base. Humans prefer base 10, so they've make that the default.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 8:36 AM,   wrote:
> Den tisdag 7 april 2015 kl. 16:30:15 UTC+2 skrev Denis McMahon:
>> On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote:
>>
>> > On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:
>>
>> >> I want todo faster baseconversion for very big bases like base 1 000
>> >> 000, so instead of adding up digits i search it.
>>
>> > How do you know the baseconversion is the bottleneck, if you haven't
>> > written any Python code yet?
>>
>> He doesn't. He doesn't comprehend that as far as a computer is concerned
>> an integer has no specific 'base', it's only when presented in a form for
>> humans to read that it gets base information added in the representation.
>>
>> He's making these and other similar errors in the javascript groups too.
>>
>> I suspect he's one of those people that spends his time thinking up
>> elaborate solutions that he has no idea how to implement as a response to
>> dreamt up non existent problems.
>>
>> --
>> Denis McMahon, denismfmcma...@gmail.com
>
> Bullshit declare two integers in any language one 7 and one 4 and then write 
> x=7+4; if you find a programming language where that does not yield 11 tell 
> me.
>
> Integers are internally assumed to be base 10 otherwise you could not 
> calculate without giving the base.
>
> All operations on integers addition, subtraction, multiplication and division 
> assume base 10.

You're conflating the internal representation of the integer with the
formatting that is done to display the integer. When you do
"print(x)", the computer doesn't just dump the internal representation
of x onto the display. It formats x as character data and displays
*that*. For integers, the vast majority of programming languages will
do the formatting as base 10 by default, since that is the format
preferred by most humans.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Dave Angel

On 04/07/2015 10:36 AM, jonas.thornv...@gmail.com wrote:



All operations on integers addition, subtraction, multiplication and division 
assume base 10.



There have been machines where that was true, but I haven't worked on 
such for about 30 years.  On any machines I've programmed lately, the 
arithmetic is done in binary by default, and only converted to decimal 
for printing.


Not that the internal base is usually relevant, of course.

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Grant Edwards
On 2015-04-07, Chris Angelico  wrote:
> On Wed, Apr 8, 2015 at 12:36 AM,   wrote:
>
>> Integers are internally assumed to be base 10 otherwise you could not
>> calculate without giving the base.
>>
>> All operations on integers addition, subtraction, multiplication and
>> division assume base 10.
>
> You misunderstand how computers and programming languages work. What
> you're seeing there is that *integer literals* are usually in base
> 10; and actually, I can point to plenty of assembly languages where
> the default isn't base 10 (it's usually base 16 (hexadecimal) on IBM
> PCs, and probably base 8 (octal) on big iron).

I'd be curious to see some of those assemblers. I've used dozens of
assemblers over the years for everything from microprocessors with a
few hundred bytes of memory to mini-computers and mainframes.  I've
never seen one that didn't default to base 10 for integer literals.

I'm not saying they don't exist, just that it would be interesting to
see an example of one.

-- 
Grant Edwards   grant.b.edwardsYow! I'm a fuschia bowling
  at   ball somewhere in Brittany
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-07 Thread Tim Golden
On 07/04/2015 15:52, Tim Golden wrote:
> On 07/04/2015 15:35, Khyati wrote:
>> On Tuesday, April 7, 2015 at 10:31:47 AM UTC-4, Chris Angelico wrote:
>>> On Wed, Apr 8, 2015 at 12:15 AM, Khyati wrote:
 Thanks for taking a look, Chris.
 The error trace:
 traceback (most recent call last):
  File "MonitorRegistry.py", line 18, in 
process_created = watcher()
  File "C:\Python27\lib\site-packages\wmi.py", line 1195, in __call__
handle_com_error ()
  File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
 _wmi: >>> (0, u'SWbemPropertySet', u'Not found ', None, 0, -2147217406), None)>
>>>
>>> It looks to me like this is a thin wrapper around the underlying API
>>> call, and you're getting back an error from the lower-level services.
>>> The way this reads, there might well not be an
>>> HKLM\Software\Temp\Name; maybe the ValueName is what's wrong here?
>>>
>>> Someone somewhere knows more than I do, but if you can't find that
>>> someone here on python-list, you might be able to find some help on
>>> Stack Overflow or another mailing list, from people who know how to do
>>> this kind of thing in a different language. You'd have to translate
>>> their suggestions back into Python, but when the wrappers are thin
>>> enough, that's usually not too hard.
>>>
>>> ChrisA
>>
>> HKLM\Software\Temp\Name exists since the event is caught correctly only when 
>> I change that key.
>> i'll keep looking :)
>>
> 
> Hi, Khyati.
> 
> Unfortunately, extrinsic events don't come with much information. As you
> can see from the MSDN description:
> 
> https://msdn.microsoft.com/en-us/library/aa390355%28v=vs.85%29.aspx
> 
> they're not linked to WMI objects internally (which the intrinsic events
> are) so all they can do is echo back to you details of what changed --
> which will usually be the thing you were asking about in the first place!
> 
> So the Python wrapper doesn't receive any TargetInstance because it's
> not a *WMI* event as such, linked to a WMI object; rather, it's an
> external event which has provided a hook for WMI to hang on to.
> 
> In this specific case, you could use the WMI Registry provider to pick
> up the current value of that registry value, but that wouldn't tell you
> what was there before or anything else. In another case, the event might
> be about some entirely external system -- such as the
> SecurityViolationEvent in the MSDN example -- which provides no WMI
> interface beyond the event itself.
> 
> Feel free to ask more, either on this list or on the win32-specific
> Python list:
> 
> https://mail.python.org/mailman/listinfo/python-win32
> 
> (I'm not often free to answer questions so best to use the public forums
> where more people will be able to help).


Forgot to say: you can simplify your code a little as well:


import wmi

c = wmi.WMI(namespace="root/default")
watcher = c.RegistryValueChangeEvent(Hive="HKEY_LOCAL_MACHINE",
KeyPath=r"Software\\Temp", ValueName="Name")

event = watcher()



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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Dave Angel

On 04/07/2015 11:05 AM, Grant Edwards wrote:

On 2015-04-07, Chris Angelico  wrote:

On Wed, Apr 8, 2015 at 12:36 AM,   wrote:


Integers are internally assumed to be base 10 otherwise you could not
calculate without giving the base.

All operations on integers addition, subtraction, multiplication and
division assume base 10.


You misunderstand how computers and programming languages work. What
you're seeing there is that *integer literals* are usually in base
10; and actually, I can point to plenty of assembly languages where
the default isn't base 10 (it's usually base 16 (hexadecimal) on IBM
PCs, and probably base 8 (octal) on big iron).


I'd be curious to see some of those assemblers. I've used dozens of
assemblers over the years for everything from microprocessors with a
few hundred bytes of memory to mini-computers and mainframes.  I've
never seen one that didn't default to base 10 for integer literals.

I'm not saying they don't exist, just that it would be interesting to
see an example of one.



I can't "show" it to you, but the assembler used to write microcode on 
the Wang labs 200VP and 2200MVP used hex for all its literals.  I wrote 
the assembler (and matching debugger-assembler), and if we had needed 
other bases I would have taken an extra day to add them in.


That assembler was not available to our customers, as the machine 
shipped with the microcode in readonly form.  Not quite as readonly as 
the Intel processors of today, of course.



Additionally, the MSDOS DEBUG program used hex to enter in its literals, 
if i recall correctly.  Certainly when it disassembled code, it was in hex.



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


Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-07 Thread Khyati
Thanks TJG for your reply. 
I guess at this point the question is why is the event not returned to wmi as 
Extrinsic. May be I should explicitly initialize the class _wmi_watcher and set 
self.is_extrinsic = True?


Thanks
Khyati

On Tuesday, April 7, 2015 at 11:18:39 AM UTC-4, Tim Golden wrote:
> On 07/04/2015 15:52, Tim Golden wrote:
> > On 07/04/2015 15:35, Khyati wrote:
> >> On Tuesday, April 7, 2015 at 10:31:47 AM UTC-4, Chris Angelico wrote:
> >>> On Wed, Apr 8, 2015 at 12:15 AM, Khyati wrote:
>  Thanks for taking a look, Chris.
>  The error trace:
>  traceback (most recent call last):
>   File "MonitorRegistry.py", line 18, in 
> process_created = watcher()
>   File "C:\Python27\lib\site-packages\wmi.py", line 1195, in __call__
> handle_com_error ()
>   File "C:\Python27\lib\site-packages\wmi.py", line 241, in 
>  handle_com_error
> raise klass (com_error=err)
>  _wmi:   (0, u'SWbemPropertySet', u'Not found ', None, 0, -2147217406), None)>
> >>>
> >>> It looks to me like this is a thin wrapper around the underlying API
> >>> call, and you're getting back an error from the lower-level services.
> >>> The way this reads, there might well not be an
> >>> HKLM\Software\Temp\Name; maybe the ValueName is what's wrong here?
> >>>
> >>> Someone somewhere knows more than I do, but if you can't find that
> >>> someone here on python-list, you might be able to find some help on
> >>> Stack Overflow or another mailing list, from people who know how to do
> >>> this kind of thing in a different language. You'd have to translate
> >>> their suggestions back into Python, but when the wrappers are thin
> >>> enough, that's usually not too hard.
> >>>
> >>> ChrisA
> >>
> >> HKLM\Software\Temp\Name exists since the event is caught correctly only 
> >> when I change that key.
> >> i'll keep looking :)
> >>
> > 
> > Hi, Khyati.
> > 
> > Unfortunately, extrinsic events don't come with much information. As you
> > can see from the MSDN description:
> > 
> > https://msdn.microsoft.com/en-us/library/aa390355%28v=vs.85%29.aspx
> > 
> > they're not linked to WMI objects internally (which the intrinsic events
> > are) so all they can do is echo back to you details of what changed --
> > which will usually be the thing you were asking about in the first place!
> > 
> > So the Python wrapper doesn't receive any TargetInstance because it's
> > not a *WMI* event as such, linked to a WMI object; rather, it's an
> > external event which has provided a hook for WMI to hang on to.
> > 
> > In this specific case, you could use the WMI Registry provider to pick
> > up the current value of that registry value, but that wouldn't tell you
> > what was there before or anything else. In another case, the event might
> > be about some entirely external system -- such as the
> > SecurityViolationEvent in the MSDN example -- which provides no WMI
> > interface beyond the event itself.
> > 
> > Feel free to ask more, either on this list or on the win32-specific
> > Python list:
> > 
> > https://mail.python.org/mailman/listinfo/python-win32
> > 
> > (I'm not often free to answer questions so best to use the public forums
> > where more people will be able to help).
> 
> 
> Forgot to say: you can simplify your code a little as well:
> 
> 
> import wmi
> 
> c = wmi.WMI(namespace="root/default")
> watcher = c.RegistryValueChangeEvent(Hive="HKEY_LOCAL_MACHINE",
> KeyPath=r"Software\\Temp", ValueName="Name")
> 
> event = watcher()
> 
> 
> 
> TJG
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Chris Angelico
On Wed, Apr 8, 2015 at 1:23 AM, Dave Angel  wrote:
> Additionally, the MSDOS DEBUG program used hex to enter in its literals, if
> i recall correctly.  Certainly when it disassembled code, it was in hex.

Indeed, and that's where I learned 80x86 assembly coding (I didn't
have an actual assembler at the time). DEBUG didn't even have the
option of using other bases; other assemblers might give you "decimal
by default, or adorn them for other bases" (eg MASM's &H notation),
but DEBUG forced you to convert to hex manually.

Although, to be fair, DEBUG was said to have a "mini-assembler" built
in. It was never designed to replace actual assemblers, AFAIK. I just
happened to use it that way. :)

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


[SerialConnection] Help

2015-04-07 Thread Hugo Caldas
Hi.

I want to connect to a serial port, read and write the port values with
multi threading and save them in random variables in python 3.4.
Where can I found information to do that?

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 16:32:56 UTC+2 skrev Ian:
> On Tue, Apr 7, 2015 at 3:44 AM,   wrote:
> >
> >
> > I want todo faster baseconversion for very big bases like base 1 000 000, 
> > so instead of adding up digits i search it.
> >
> > I need the fastest algorithm to find the relation to a decimal number.
> > Digmult is an instance of base at a digitplace (base^x) what i try to find 
> > is the digit for the below condition is true and the loop break.
> >
> >
> > *
> > for (digit=0;digit<=base;digit++) {
> >if((digit+1)*digmult>decNumber)break;
> > }
> > *
> >
> > So i am looking for the digit where following condition true.
> >
> > if((digit)*digmultdecNumber) then 
> > BREAK;
> 
> I'm not sure that I understand what it is that you're trying to
> accomplish. Are you trying to find the digits without using division
> because "division is slow"? If that's the case, then let me show you
> something.
> 
> $ python -m timeit -s "n = 1523837293" "n // 100"
> 100 loops, best of 3: 0.286 usec per loop
> 
> $ python -m timeit -s "n = 1523" "n * 100; (n+1) * 100"
> 100 loops, best of 3: 0.455 usec per loop
> 
> In Python, one addition and two multiplications are already slower
> than a single division. The only way you're going to beat division by
> using trial multiplication is if the first digit that you try is
> always correct. To do that, you would need an oracle feeding your
> search algorithm, and then you might as well just use the oracle.
> 
> > One could start at half base searching, but then i Think i've read that 
> > using 1/3 closing in faster?
> 
> Do you mean binary search? That would be an improvement over the
> linear search algorithm you've shown. Whether a trinary search might
> be faster would depend on the distribution of the numbers you expect.
> If they're evenly distributed, it will be slower.
> 
> > I Think also i remember that if the search space so big that at least 22 or 
> > 23 guesses, needed.A random Oracle may even faster?
> >
> > Just pick up a number and get lucky, is it any truth to that?
> 
> On average, a random Oracle with a search space of 100 will need
> 100 guesses.

Well of course you use same principles like a binary search setting min and 
max, closing in on the digit. In this case the searched numbers  > base^exp  
and number< base^exp+1.

But since the search is within large bases upto 32-bit space, so base 
4294967295 is the biggest allowed. I need to find the nearest less exp in base 
for each (lets call them pseudo digits). But as you see there it will take time 
to add them up. So better doing a binary search, you know min-max half 
(iteration). You can do the same for a random oracle min max within range, and 
if the number of tries in general over 22 i think a random oracle do it better 
than a binary search. 

It was a long time since i did this, but i do know there is a threshold where 
searching min max with the oracle will be faster than the binary search.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 17:00:53 UTC+2 skrev MRAB:
> On 2015-04-07 15:36, jonas.thornv...@gmail.com wrote:
> > Den tisdag 7 april 2015 kl. 16:30:15 UTC+2 skrev Denis McMahon:
> >> On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote:
> >>
> >>> On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:
> >>
>  I want todo faster baseconversion for very big bases like base
>  1 000 000, so instead of adding up digits i search it.
> >>
> >>> How do you know the baseconversion is the bottleneck, if you
> >>> haven't written any Python code yet?
> >>
> >> He doesn't. He doesn't comprehend that as far as a computer is
> >> concerned an integer has no specific 'base', it's only when
> >> presented in a form for humans to read that it gets base
> >> information added in the representation.
> >>
> >> He's making these and other similar errors in the javascript groups
> >> too.
> >>
> >> I suspect he's one of those people that spends his time thinking
> >> up elaborate solutions that he has no idea how to implement as a
> >> response to dreamt up non existent problems.
> >>
> > Bullshit declare two integers in any language one 7 and one 4 and
> > then write x=7+4; if you find a programming language where that does
> > not yield 11 tell me.
> >
> > Integers are internally assumed to be base 10 otherwise you could not
> > calculate without giving the base.
> >
> > All operations on integers addition, subtraction, multiplication and
> > division assume base 10.
> >
> Sorry to say this, but that's nonsense.
> 
> It doesn't matter what base it's working in internally; usually it's
> base 2 (binary), because that's simpler to implement.
> 
> It's only when you're converting from or to text that you need specify
> a base. Humans prefer base 10, so they've make that the default.

No that is not what i am saying, i am saying if you do operations on two 
integers the machine will assume base 10.
-- 
https://mail.python.org/mailman/listinfo/python-list


Euler module under python 2.7 and 3.4 instalation...

2015-04-07 Thread blue
Dear friends .
I want to install Euler module under python 2.7 and / or 3.4 version.
I try pip and pip 3.4 but seam not working for me.
I need some help with this .
Thank you . Regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 17:07:36 UTC+2 skrev Ian:
> On Tue, Apr 7, 2015 at 8:36 AM,   wrote:
> > Den tisdag 7 april 2015 kl. 16:30:15 UTC+2 skrev Denis McMahon:
> >> On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote:
> >>
> >> > On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:
> >>
> >> >> I want todo faster baseconversion for very big bases like base 1 000
> >> >> 000, so instead of adding up digits i search it.
> >>
> >> > How do you know the baseconversion is the bottleneck, if you haven't
> >> > written any Python code yet?
> >>
> >> He doesn't. He doesn't comprehend that as far as a computer is concerned
> >> an integer has no specific 'base', it's only when presented in a form for
> >> humans to read that it gets base information added in the representation.
> >>
> >> He's making these and other similar errors in the javascript groups too.
> >>
> >> I suspect he's one of those people that spends his time thinking up
> >> elaborate solutions that he has no idea how to implement as a response to
> >> dreamt up non existent problems.
> >>
> >> --
> >> Denis McMahon, denismfmcma...@gmail.com
> >
> > Bullshit declare two integers in any language one 7 and one 4 and then 
> > write x=7+4; if you find a programming language where that does not yield 
> > 11 tell me.
> >
> > Integers are internally assumed to be base 10 otherwise you could not 
> > calculate without giving the base.
> >
> > All operations on integers addition, subtraction, multiplication and 
> > division assume base 10.
> 
> You're conflating the internal representation of the integer with the
> formatting that is done to display the integer. When you do
> "print(x)", the computer doesn't just dump the internal representation
> of x onto the display. It formats x as character data and displays
> *that*. For integers, the vast majority of programming languages will
> do the formatting as base 10 by default, since that is the format
> preferred by most humans.

No i don't i say the operations assume base ten other wise INT A=7,B=4 
Calculate C=A+B would not yield 11 as an answer. The programming languages 
assume integer operations are done in base 10, at least the one where you can 
not specify in what base the integer arithmetic is done. And there probably is 
such languages, Python maybe?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread MRAB

On 2015-04-07 16:05, Grant Edwards wrote:

On 2015-04-07, Chris Angelico  wrote:

On Wed, Apr 8, 2015 at 12:36 AM,   wrote:


Integers are internally assumed to be base 10 otherwise you could not
calculate without giving the base.

All operations on integers addition, subtraction, multiplication and
division assume base 10.


You misunderstand how computers and programming languages work. What
you're seeing there is that *integer literals* are usually in base
10; and actually, I can point to plenty of assembly languages where
the default isn't base 10 (it's usually base 16 (hexadecimal) on IBM
PCs, and probably base 8 (octal) on big iron).


I'd be curious to see some of those assemblers. I've used dozens of
assemblers over the years for everything from microprocessors with a
few hundred bytes of memory to mini-computers and mainframes.  I've
never seen one that didn't default to base 10 for integer literals.

I'm not saying they don't exist, just that it would be interesting to
see an example of one.


I have a book called "Choosing and using 4 Bit Microcontrollers" by
Philip McDowell. In it is an example assembly listing for an OKI 6351
microcontroller that uses unadorned hexadecimal literals.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-07 Thread Khyati
Resolved:
watcher = c.watch_for(raw_wql=raw_wql,wmi_class = "RegistryValueChangeEvent")
is the right way - instead of wmi_class = __ExtrinsicEvent

Thanks, everyone.


On Tuesday, April 7, 2015 at 11:30:33 AM UTC-4, Khyati wrote:
> Thanks TJG for your reply. 
> I guess at this point the question is why is the event not returned to wmi as 
> Extrinsic. May be I should explicitly initialize the class _wmi_watcher and 
> set self.is_extrinsic = True?
> 
> 
> Thanks
> Khyati
> 
> On Tuesday, April 7, 2015 at 11:18:39 AM UTC-4, Tim Golden wrote:
> > On 07/04/2015 15:52, Tim Golden wrote:
> > > On 07/04/2015 15:35, Khyati wrote:
> > >> On Tuesday, April 7, 2015 at 10:31:47 AM UTC-4, Chris Angelico wrote:
> > >>> On Wed, Apr 8, 2015 at 12:15 AM, Khyati wrote:
> >  Thanks for taking a look, Chris.
> >  The error trace:
> >  traceback (most recent call last):
> >   File "MonitorRegistry.py", line 18, in 
> > process_created = watcher()
> >   File "C:\Python27\lib\site-packages\wmi.py", line 1195, in __call__
> > handle_com_error ()
> >   File "C:\Python27\lib\site-packages\wmi.py", line 241, in 
> >  handle_com_error
> > raise klass (com_error=err)
> >  _wmi:  >  occurred.', (0, u'SWbemPropertySet', u'Not found ', None, 0, 
> >  -2147217406), None)>
> > >>>
> > >>> It looks to me like this is a thin wrapper around the underlying API
> > >>> call, and you're getting back an error from the lower-level services.
> > >>> The way this reads, there might well not be an
> > >>> HKLM\Software\Temp\Name; maybe the ValueName is what's wrong here?
> > >>>
> > >>> Someone somewhere knows more than I do, but if you can't find that
> > >>> someone here on python-list, you might be able to find some help on
> > >>> Stack Overflow or another mailing list, from people who know how to do
> > >>> this kind of thing in a different language. You'd have to translate
> > >>> their suggestions back into Python, but when the wrappers are thin
> > >>> enough, that's usually not too hard.
> > >>>
> > >>> ChrisA
> > >>
> > >> HKLM\Software\Temp\Name exists since the event is caught correctly only 
> > >> when I change that key.
> > >> i'll keep looking :)
> > >>
> > > 
> > > Hi, Khyati.
> > > 
> > > Unfortunately, extrinsic events don't come with much information. As you
> > > can see from the MSDN description:
> > > 
> > > https://msdn.microsoft.com/en-us/library/aa390355%28v=vs.85%29.aspx
> > > 
> > > they're not linked to WMI objects internally (which the intrinsic events
> > > are) so all they can do is echo back to you details of what changed --
> > > which will usually be the thing you were asking about in the first place!
> > > 
> > > So the Python wrapper doesn't receive any TargetInstance because it's
> > > not a *WMI* event as such, linked to a WMI object; rather, it's an
> > > external event which has provided a hook for WMI to hang on to.
> > > 
> > > In this specific case, you could use the WMI Registry provider to pick
> > > up the current value of that registry value, but that wouldn't tell you
> > > what was there before or anything else. In another case, the event might
> > > be about some entirely external system -- such as the
> > > SecurityViolationEvent in the MSDN example -- which provides no WMI
> > > interface beyond the event itself.
> > > 
> > > Feel free to ask more, either on this list or on the win32-specific
> > > Python list:
> > > 
> > > https://mail.python.org/mailman/listinfo/python-win32
> > > 
> > > (I'm not often free to answer questions so best to use the public forums
> > > where more people will be able to help).
> > 
> > 
> > Forgot to say: you can simplify your code a little as well:
> > 
> > 
> > import wmi
> > 
> > c = wmi.WMI(namespace="root/default")
> > watcher = c.RegistryValueChangeEvent(Hive="HKEY_LOCAL_MACHINE",
> > KeyPath=r"Software\\Temp", ValueName="Name")
> > 
> > event = watcher()
> > 
> > 
> > 
> > TJG
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SerialConnection] Help

2015-04-07 Thread Ian Kelly
On Apr 7, 2015 9:43 AM, "Hugo Caldas"  wrote:
>
> Hi.
>
> I want to connect to a serial port, read and write the port values with
multi threading and save them in random variables in python 3.4.
> Where can I found information to do that?

You can use the pyserial third-party module to do the serial port
communication and the threading module from the standard library for
multithreading.

You'll have to elaborate on what you mean by "random variables".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SerialConnection] Help

2015-04-07 Thread Grant Edwards
On 2015-04-07, Hugo Caldas  wrote:

> I want to connect to a serial port, read and write the port values with
> multi threading and save them in random variables in python 3.4.
> Where can I found information to do that?

http://pyserial.sourceforge.net/pyserial.html

-- 
Grant Edwards   grant.b.edwardsYow! This ASEXUAL PIG
  at   really BOILS my BLOOD
  gmail.com... He's so ... so
   ... URGENT!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SerialConnection] Help

2015-04-07 Thread MRAB

On 2015-04-07 16:42, Hugo Caldas wrote:

Hi.

I want to connect to a serial port, read and write the port values with
multi threading and save them in random variables in python 3.4.
Where can I found information to do that?


Use the pyserial module.

The module is on PyPI:

https://pypi.python.org/pypi/pyserial

and the documentation is here:

http://pythonhosted.org//pyserial/

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 16:30:15 UTC+2 skrev Denis McMahon:
> On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote:
> 
> > On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote:
> 
> >> I want todo faster baseconversion for very big bases like base 1 000
> >> 000, so instead of adding up digits i search it.
> 
> > How do you know the baseconversion is the bottleneck, if you haven't
> > written any Python code yet?
> 
> He doesn't. He doesn't comprehend that as far as a computer is concerned 
> an integer has no specific 'base', it's only when presented in a form for 
> humans to read that it gets base information added in the representation.
> 
> He's making these and other similar errors in the javascript groups too.
> 
> I suspect he's one of those people that spends his time thinking up 
> elaborate solutions that he has no idea how to implement as a response to 
> dreamt up non existent problems.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com

Well Denis if it hasn't a base then how can you add integers, the integer 
operations assume base 10. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Dave Angel

On 04/07/2015 11:40 AM, jonas.thornv...@gmail.com wrote:

Den tisdag 7 april 2015 kl. 16:32:56 UTC+2 skrev Ian:

On Tue, Apr 7, 2015 at 3:44 AM,   wrote:



I want todo faster baseconversion for very big bases like base 1 000 000, so 
instead of adding up digits i search it.

I need the fastest algorithm to find the relation to a decimal number.
Digmult is an instance of base at a digitplace (base^x) what i try to find is 
the digit for the below condition is true and the loop break.


*
for (digit=0;digit<=base;digit++) {
if((digit+1)*digmult>decNumber)break;
}
*


   



One could start at half base searching, but then i Think i've read that using 
1/3 closing in faster?


Do you mean binary search? That would be an improvement over the
linear search algorithm you've shown. Whether a trinary search might
be faster would depend on the distribution of the numbers you expect.
If they're evenly distributed, it will be slower.


I Think also i remember that if the search space so big that at least 22 or 23 
guesses, needed.A random Oracle may even faster?

Just pick up a number and get lucky, is it any truth to that?


On average, a random Oracle with a search space of 100 will need
100 guesses.


Well of course you use same principles like a binary search setting min and max, 
closing in on the digit. In this case the searched numbers  > base^exp  and 
number< base^exp+1.

But since the search is within large bases upto 32-bit space, so base 
4294967295 is the biggest allowed. I need to find the nearest less exp in base 
for each (lets call them pseudo digits). But as you see there it will take time 
to add them up. So better doing a binary search, you know min-max half 
(iteration). You can do the same for a random oracle min max within range, and 
if the number of tries in general over 22 i think a random oracle do it better 
than a binary search.

It was a long time since i did this, but i do know there is a threshold where 
searching min max with the oracle will be faster than the binary search.



Once again, there's no point in doing a search, when a simple integer 
divide can give you the exact answer.  And there's probably no point in 
going left to right when right to left would yield a tiny, fast program.


I haven't seen one line of Python from you yet, so perhaps you're just 
yanking our chain.  I'm not here to optimize Javascript code.


Using only Python 3.4 and builtin functions, this function can be 
implemented straightforwardly in 7 lines, assuming number is nonnegative 
integer, and base is positive integer.  It definitely could be done 
smaller, but then the code might be more confusing.


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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 18:34:32 UTC+2 skrev Dave Angel:
> On 04/07/2015 11:40 AM, jonas.thornv...@gmail.com wrote:
> > Den tisdag 7 april 2015 kl. 16:32:56 UTC+2 skrev Ian:
> >> On Tue, Apr 7, 2015 at 3:44 AM,   wrote:
> >>>
> >>>
> >>> I want todo faster baseconversion for very big bases like base 1 000 000, 
> >>> so instead of adding up digits i search it.
> >>>
> >>> I need the fastest algorithm to find the relation to a decimal number.
> >>> Digmult is an instance of base at a digitplace (base^x) what i try to 
> >>> find is the digit for the below condition is true and the loop break.
> >>>
> >>>
> >>> *
> >>> for (digit=0;digit<=base;digit++) {
> >>> if((digit+1)*digmult>decNumber)break;
> >>> }
> >>> *
> >>>
> 
> >>
> >>> One could start at half base searching, but then i Think i've read that 
> >>> using 1/3 closing in faster?
> >>
> >> Do you mean binary search? That would be an improvement over the
> >> linear search algorithm you've shown. Whether a trinary search might
> >> be faster would depend on the distribution of the numbers you expect.
> >> If they're evenly distributed, it will be slower.
> >>
> >>> I Think also i remember that if the search space so big that at least 22 
> >>> or 23 guesses, needed.A random Oracle may even faster?
> >>>
> >>> Just pick up a number and get lucky, is it any truth to that?
> >>
> >> On average, a random Oracle with a search space of 100 will need
> >> 100 guesses.
> >
> > Well of course you use same principles like a binary search setting min and 
> > max, closing in on the digit. In this case the searched numbers  > base^exp 
> >  and number< base^exp+1.
> >
> > But since the search is within large bases upto 32-bit space, so base 
> > 4294967295 is the biggest allowed. I need to find the nearest less exp in 
> > base for each (lets call them pseudo digits). But as you see there it will 
> > take time to add them up. So better doing a binary search, you know min-max 
> > half (iteration). You can do the same for a random oracle min max within 
> > range, and if the number of tries in general over 22 i think a random 
> > oracle do it better than a binary search.
> >
> > It was a long time since i did this, but i do know there is a threshold 
> > where searching min max with the oracle will be faster than the binary 
> > search.
> >
> 
> Once again, there's no point in doing a search, when a simple integer 
> divide can give you the exact answer.  And there's probably no point in 
> going left to right when right to left would yield a tiny, fast program.
> 
> I haven't seen one line of Python from you yet, so perhaps you're just 
> yanking our chain.  I'm not here to optimize Javascript code.
> 
> Using only Python 3.4 and builtin functions, this function can be 
> implemented straightforwardly in 7 lines, assuming number is nonnegative 
> integer, and base is positive integer.  It definitely could be done 
> smaller, but then the code might be more confusing.
> 
> -- 
> DaveA

So you can tell me the first (higest) digit of the integer 
2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490

Using base 429496729?

How long time did it take to find it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 11:07 AM,   wrote:
> Den tisdag 7 april 2015 kl. 18:34:32 UTC+2 skrev Dave Angel:
>> Once again, there's no point in doing a search, when a simple integer
>> divide can give you the exact answer.  And there's probably no point in
>> going left to right when right to left would yield a tiny, fast program.
>>
>> I haven't seen one line of Python from you yet, so perhaps you're just
>> yanking our chain.  I'm not here to optimize Javascript code.
>>
>> Using only Python 3.4 and builtin functions, this function can be
>> implemented straightforwardly in 7 lines, assuming number is nonnegative
>> integer, and base is positive integer.  It definitely could be done
>> smaller, but then the code might be more confusing.
>>
>> --
>> DaveA
>
> So you can tell me the first (higest) digit of the integer 
> 2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490
>
> Using base 429496729?

>>> def to_base(number, base):
... digits = []
... while number > 0:
... digits.append(number % base)
... number //= base
... return digits or [0]
...
>>> to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
>>>  429496729)
[27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
79384857, 112868646, 221068759, 70871527, 416507001, 31]

> How long time did it take to find it?

About 15 microseconds.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Euler module under python 2.7 and 3.4 instalation...

2015-04-07 Thread Dave Angel

On 04/07/2015 11:39 AM, blue wrote:

Dear friends .
I want to install Euler module under python 2.7 and / or 3.4 version.
I try pip and pip 3.4 but seam not working for me.
I need some help with this .
Thank you . Regards.



You don't specify what you mean by Euler.  There are at least 3 things 
you might be talking about:


http://euler.rene-grothmann.de/index.html

https://projecteuler.net/

https://github.com/iKevinY/EulerPy

Without you telling us what you're talking about, we're not likely to be 
able to help.


If you used a pip command(s), please show us exactly what you typed, and 
what result you saw.  Use copy/paste.


And tell us what OS you're doing it on.

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Terry Reedy

On 4/7/2015 1:44 PM, Ian Kelly wrote:


def to_base(number, base):

... digits = []
... while number > 0:
... digits.append(number % base)
... number //= base
... return digits or [0]
...

to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
 429496729)

[27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
79384857, 112868646, 221068759, 70871527, 416507001, 31]
About 15 microseconds.


% and probably // call divmod internally and toss one of the results. 
Slightly faster (5.7 versus 6.1 microseconds on my machine) is


def to_base_dm(number, base):
digits = []
while number > 0:
number, rem = divmod(number, base)
digits.append(rem)
return digits or [0]

--
Terry Jan Reedy

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy  wrote:
> On 4/7/2015 1:44 PM, Ian Kelly wrote:
>
> def to_base(number, base):
>>
>> ... digits = []
>> ... while number > 0:
>> ... digits.append(number % base)
>> ... number //= base
>> ... return digits or [0]
>> ...
>
>
> to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
> 429496729)
>>
>> [27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
>> 79384857, 112868646, 221068759, 70871527, 416507001, 31]
>> About 15 microseconds.
>
>
> % and probably // call divmod internally and toss one of the results.
> Slightly faster (5.7 versus 6.1 microseconds on my machine) is

Not on my box.

$ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
1000 loops, best of 3: 0.105 usec per loop
$ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
1000 loops, best of 3: 0.124 usec per loop
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Chris Angelico
On Wed, Apr 8, 2015 at 5:19 AM, Ian Kelly  wrote:
>> % and probably // call divmod internally and toss one of the results.
>> Slightly faster (5.7 versus 6.1 microseconds on my machine) is
>
> Not on my box.
>
> $ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
> 1000 loops, best of 3: 0.105 usec per loop
> $ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
> 1000 loops, best of 3: 0.124 usec per loop

Nor mine, though eliminating the global lookup cuts some of the time:

rosuav@sikorsky:~$ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
100 loops, best of 3: 0.231 usec per loop
rosuav@sikorsky:~$ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
100 loops, best of 3: 0.305 usec per loop
rosuav@sikorsky:~$ python3 -m timeit -s "n = 100; x = 42; dm =
divmod" "dm(n,x)"
100 loops, best of 3: 0.26 usec per loop

But this is microbenchmarking. It's pretty pointless.

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 1:19 PM, Ian Kelly  wrote:
> On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy  wrote:
>> On 4/7/2015 1:44 PM, Ian Kelly wrote:
>>
>> def to_base(number, base):
>>>
>>> ... digits = []
>>> ... while number > 0:
>>> ... digits.append(number % base)
>>> ... number //= base
>>> ... return digits or [0]
>>> ...
>>
>>
>> to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
>> 429496729)
>>>
>>> [27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
>>> 79384857, 112868646, 221068759, 70871527, 416507001, 31]
>>> About 15 microseconds.
>>
>>
>> % and probably // call divmod internally and toss one of the results.
>> Slightly faster (5.7 versus 6.1 microseconds on my machine) is
>
> Not on my box.
>
> $ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
> 1000 loops, best of 3: 0.105 usec per loop
> $ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
> 1000 loops, best of 3: 0.124 usec per loop

But curiously, if I time the whole function, then my results mirror
yours; I wonder why that is. I don't see anything obvious in the
disassembly that would explain it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ben Bacarisse
Ian Kelly  writes:

> On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy  wrote:
>> On 4/7/2015 1:44 PM, Ian Kelly wrote:
>>
>> def to_base(number, base):
>>>
>>> ... digits = []
>>> ... while number > 0:
>>> ... digits.append(number % base)
>>> ... number //= base
>>> ... return digits or [0]
>>> ...
>>
>>
>> to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
>> 429496729)
>>>
>>> [27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
>>> 79384857, 112868646, 221068759, 70871527, 416507001, 31]
>>> About 15 microseconds.
>>
>>
>> % and probably // call divmod internally and toss one of the results.
>> Slightly faster (5.7 versus 6.1 microseconds on my machine) is
>
> Not on my box.
>
> $ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
> 1000 loops, best of 3: 0.105 usec per loop
> $ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
> 1000 loops, best of 3: 0.124 usec per loop

I get similar results, but the times switch over when n is large enough
to become a bignum.

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


Could not find any downloads that satisfy the requirement novaclient

2015-04-07 Thread kurt_heiss
Hi-

While trying to install an OpenStack client on Mac OSX, I get the following:

SymMacToolkit-C02N4H9DG3QD:/ kurt_heiss$ sudo pip install novaclient
Password:
The directory '/Users/kurt_heiss/Library/Logs/pip' or its parent directory is 
not owned by the current user and the debug log has been disabled. Please check 
the permissions and owner of that directory. If executing pip with sudo, you 
may want the -H flag.
The directory '/Users/kurt_heiss/Library/Caches/pip/http' or its parent 
directory is not owned by the current user and the cache has been disabled. 
Please check the permissions and owner of that directory. If executing pip with 
sudo, you may want the -H flag.
The directory '/Users/kurt_heiss/Library/Caches/pip/http' or its parent 
directory is not owned by the current user and the cache has been disabled. 
Please check the permissions and owner of that directory. If executing pip with 
sudo, you may want the -H flag.
Collecting novaclient
  Could not find any downloads that satisfy the requirement novaclient
  No distributions at all found for novaclient
SymMacToolkit-C02N4H9DG3QD:/ kurt_heiss$ 

I changed the permissions on the identified folders as well as tried the -H 
option to no positive result.

Anybody encounter this issue or suggest a possible workaround?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 9:40 AM,   wrote:
> Well of course you use same principles like a binary search setting min and 
> max, closing in on the digit. In this case the searched numbers  > base^exp  
> and number< base^exp+1.
>
> But since the search is within large bases upto 32-bit space, so base 
> 4294967295 is the biggest allowed. I need to find the nearest less exp in 
> base for each (lets call them pseudo digits). But as you see there it will 
> take time to add them up. So better doing a binary search, you know min-max 
> half (iteration). You can do the same for a random oracle min max within 
> range, and if the number of tries in general over 22 i think a random oracle 
> do it better than a binary search.

Okay, so you're talking about doing a binary search but picking the
partition point randomly instead of evenly?

> It was a long time since i did this, but i do know there is a threshold where 
> searching min max with the oracle will be faster than the binary search.

I don't know where you got this idea from, but it's fiction. If you
split the space in half, then you are always reducing the amount of
work remaining by a factor of 2, and the total work is O(log n). If
you do an uneven split, then while you will sometimes make a good
partition and reduce the amount of work by more than a factor of two,
more often the target will be in the larger subspace and you will have
reduced the amount of work by less than a factor of two. In the worst
case of this, you only remove one element from the search space at a
time and end up with a linear search.

As a demonstration of this, here's a function which does a binary
search for a number in a range and returns the number of partitions it
had to perform to find the number:

>>> def binsearch(n, min, max):
...   if min == max: return 0
...   med = (max + min) // 2
...   if n <= med:
... return 1 + binsearch(n, min, med)
...   else:
... return 1 + binsearch(n, med+1, max)
...

And here's the average number of partitions needed to find a number in
various ranges:

>>> sum(binsearch(i, 1, n) for i in range(1, n+1)) / n
16.68928
>>> n = 100
>>> sum(binsearch(i, 1, n) for i in range(1, n+1)) / n
19.951424
>>> n = 1000
>>> sum(binsearch(i, 1, n) for i in range(1, n+1)) / n
23.3222784

Now let's try a variant function that splits the range at one third
instead of evenly:

>>> def trisearch(n, min, max):
... if min == max: return 0
... tern = (min + min + max) // 3
... if n <= tern:
... return 1 + trisearch(n, min, tern)
... else:
... return 1 + trisearch(n, tern+1, max)
...
>>> n = 10
>>> sum(trisearch(i, 1, n) for i in range(1, n+1)) / n
17.88387
>>> n = 100
>>> sum(trisearch(i, 1, n) for i in range(1, n+1)) / n
21.502276
>>> n = 1000
>>> sum(trisearch(i, 1, n) for i in range(1, n+1)) / n
25.1157592

The ternary version invariably takes more partitions on average to
find the goal number. Now let's try a third variant that partitions
the range randomly:

>>> def randsearch(n, min, max):
... if min == max: return 0
... part = randrange(min, max)
... if n <= part:
... return 1 + randsearch(n, min, part)
... else:
... return 1 + randsearch(n, part+1, max)
...
>>> n = 10
>>> sum(randsearch(i, 1, n) for i in range(1, n+1)) / n
22.17863
>>> n = 100
>>> sum(randsearch(i, 1, n) for i in range(1, n+1)) / n
26.78371
>>> n = 1000
>>> sum(randsearch(i, 1, n) for i in range(1, n+1)) / n
31.3916557

As you can see, this one does a lot worse on average, and at n=1e6
it's already performing worse than either of the previous versions did
at n=1e7.  I'm not even going to try this for n=1e8 because it would
take too long to run.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Mark Lawrence

On 07/04/2015 17:33, Dave Angel wrote:

On 04/07/2015 11:40 AM, jonas.thornv...@gmail.com wrote:

I haven't seen one line of Python from you yet, so perhaps you're just
yanking our chain.



This wouldn't surprise me, he's the guy who refused point blank to 
modify his use of gg some 18 months ago.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Serhiy Storchaka

On 07.04.15 22:28, Ian Kelly wrote:

On Tue, Apr 7, 2015 at 1:19 PM, Ian Kelly  wrote:

On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy  wrote:

% and probably // call divmod internally and toss one of the results.
Slightly faster (5.7 versus 6.1 microseconds on my machine) is


Not on my box.

$ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
1000 loops, best of 3: 0.105 usec per loop
$ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
1000 loops, best of 3: 0.124 usec per loop


But curiously, if I time the whole function, then my results mirror
yours; I wonder why that is. I don't see anything obvious in the
disassembly that would explain it.


Try large numbers.

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


Re: Help with pipes, buffering and pseudoterminals

2015-04-07 Thread Cameron Simpson

On 07Apr2015 20:38, Chris Angelico  wrote:

On Tue, Apr 7, 2015 at 3:48 PM, Cameron Simpson  wrote:

The operating system arranges the commection of the shell to the terminal.
Your usual program has by default a stdin, stdout and stderr. These are
_all_ the same file handle, duplicated to each of the three file descriptors
0, 1 and 2 respectively. On the operating system side, the OS has performed
_one_ open() call on the terminal device and handed the caller a single file
descriptor. The caller then calls dup() (or modernly, dup2()) to present the
open terminal as stdin, stdout and stderr.


Really? I can believe that stdout and stderr are initially duplicates,
but stdin as well? Isn't stdin opened for reading only, and
stdout/stderr for writing only?


No. Have a look with lsof:

 lsof -p $$

in a terminal.


I grew up on DOS and OS/2, not on Unix, so maybe there's a massive
simplification here that I'm not aware of. That'd be pretty clean and
tidy if what you say is the case!


The setup is very simple: open the tty for read/write, close everything else, 
dup the tty to fds 0, 1 and 2, make the tty the child's controlling terminal.  
There's a little housekeeping like setting tty modes (erase and kill 
characters, so forth) and putting the child in its own process group, but the 
basics are as stated.


Cheers,
Cameron Simpson 

TeX: When you pronounce it correctly to your computer, the terminal may
become slightly moist. - D. E. Knuth.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help with pipes, buffering and pseudoterminals

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 4:06 PM, Cameron Simpson  wrote:
> On 07Apr2015 20:38, Chris Angelico  wrote:
>>
>> On Tue, Apr 7, 2015 at 3:48 PM, Cameron Simpson  wrote:
>>>
>>> The operating system arranges the commection of the shell to the
>>> terminal.
>>> Your usual program has by default a stdin, stdout and stderr. These are
>>> _all_ the same file handle, duplicated to each of the three file
>>> descriptors
>>> 0, 1 and 2 respectively. On the operating system side, the OS has
>>> performed
>>> _one_ open() call on the terminal device and handed the caller a single
>>> file
>>> descriptor. The caller then calls dup() (or modernly, dup2()) to present
>>> the
>>> open terminal as stdin, stdout and stderr.
>>
>>
>> Really? I can believe that stdout and stderr are initially duplicates,
>> but stdin as well? Isn't stdin opened for reading only, and
>> stdout/stderr for writing only?
>
>
> No. Have a look with lsof:
>
>  lsof -p $$
>
> in a terminal.

sys.stdin and sys.stdout are distinct, uni-directional io objects. At
a lower level though, the only thing stopping you from calling
os.write on fd 0 or os.read on fd 1 or 2 is convention.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Steven D'Aprano
On Wed, 8 Apr 2015 12:36 am, jonas.thornv...@gmail.com wrote:

> Bullshit declare two integers in any language one 7 and one 4 and then
> write x=7+4; if you find a programming language where that does not yield
> 11 tell me.

In Forth, you can set the base to any arbitrary integer (within reason).

steve@orac:/home/steve$ gforth
Gforth 0.7.0, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
7 4 + . 11  ok
hex  ok
7 4 + . B  ok
7 4 +   ok
2 base !  ok
. 1011  ok


The dot . prints the value on the top of the stack. In Python terms, the
closest equivalent would be:

print (7 + 4)  # prints 11 by default
# set the base to hex
print (7 + 4)  # prints B
x = 7 + 4
# set the base to 2
print (x)  # prints 1011


except that Python doesn't allow you to change the base used by ints, it is
always decimal.

In Forth, however, setting the base doesn't just change the *display* of
integers, it also changes how you enter them:

3
:7: Undefined word
>>>3<<<
Backtrace:
$B7252EDC throw
$B725F638 no.extensions
$B7253054 interpreter-notfound1
  ok


So in base 2 mode, it doesn't recognise 3 as a number. If I want to enter
three, I have to enter it in binary:

11  ok
decimal  ok
. 3  ok



> Integers are internally assumed to be base 10 otherwise you could not
> calculate without giving the base.


That is *absolutely not* the case in Forth. It's not even the case in
Python: integers are actually stored in either binary (base 2) or some very
large base, I think equivalent to base 256, depending on the version of
Python and the size of the int. 


> All operations on integers addition, subtraction, multiplication and
> division assume base 10.

That's just ridiculous.

In Python, like most other languages, the only thing which assumes base 10
is entry and printing of integers.




-- 
Steven

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den tisdag 7 april 2015 kl. 21:27:20 UTC+2 skrev Ben Bacarisse:
> Ian Kelly  writes:
> 
> > On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy  wrote:
> >> On 4/7/2015 1:44 PM, Ian Kelly wrote:
> >>
> >> def to_base(number, base):
> >>>
> >>> ... digits = []
> >>> ... while number > 0:
> >>> ... digits.append(number % base)
> >>> ... number //= base
> >>> ... return digits or [0]
> >>> ...
> >>
> >>
> >> to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
> >> 429496729)
> >>>
> >>> [27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
> >>> 79384857, 112868646, 221068759, 70871527, 416507001, 31]
> >>> About 15 microseconds.
> >>
> >>
> >> % and probably // call divmod internally and toss one of the results.
> >> Slightly faster (5.7 versus 6.1 microseconds on my machine) is
> >
> > Not on my box.
> >
> > $ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
> > 1000 loops, best of 3: 0.105 usec per loop
> > $ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
> > 1000 loops, best of 3: 0.124 usec per loop
> 
> I get similar results, but the times switch over when n is large enough
> to become a bignum.
> 
> -- 
> Ben.

I am not sure you guys realised, that althoug the size of the factors to 
muliply expands according to base^(exp+1) for each digitplace the number of 
comparissons needed to reach the digit place (multiple of base^exp+1) is 
constant with my approach/method.
-- 
https://mail.python.org/mailman/listinfo/python-list


Code critique please

2015-04-07 Thread kai . peters
I just wrote this bit (coming from Pascal) and am wondering how seasoned Python 
programmers would have done the same? Anything terribly non-python?

As always, thanks for all input.

K



"""
 Creates a PNG image from EPD file
"""

import os, sys
from PIL import Image, ImageFont, ImageDraw

# -
def RenderByte(draw, byte, x, y):

blist = list(bin(byte).lstrip('0b')) # turn byte into list with 8 elements, 
c = 0# each representing one bit
for bit in blist:   
if bit:
draw.point((x + c, y), fcolor)

c += 1
return

# -
def EPD_2_Image(edpfilename, imagefilename):

# get out of here if EPD file not present
if not os.path.isfile(epdfilename):
print 'file not found: ' + edpfilename
return

# is this a valid EPD file?
filesize = os.path.getsize(epdfilename)
if (((xdim / 8) * ydim) + header) <> filesize:
print 'incorrect file size: ' + edpfilename
return

# blow old destination file away 
if os.path.isfile(imagefilename):
print 'deleting old dest. file: ' + imagefilename
os.remove(imagefilename)

print 'processing...'

# set up PIL objects
img  = Image.new('1', (xdim, ydim), bcolor)   # '1' = Bi-tonal image
draw = ImageDraw.Draw(img)

# read entire EPD file into byte array (without the header)
content = bytearray(open(epdfilename, 'rb').read())[16:] 
 
# image coord origin at top/left according to PIL documentation
pos = 0
for y in range(ydim): 
x = 0
for byte in range(xdim / 8):   # 8 pixels 'stuffed' into one byte
RenderByte(draw, content[pos], x, y)
pos += 1   
x   += 8

img.save(imagefilename)   # format is inferred from given extension
print 'done.'

return
# -

xdim   = 1024
ydim   = 1280
header = 16
black  = 0
white  = 1
bcolor = black
fcolor = white

epdfilename   = 'c:\\temp\\drawtest2.epd'
imagefilename = 'c:\\temp\\drawtest2.png'

EPD_2_Image(epdfilename, imagefilename)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Cameron Simpson

On 08Apr2015 08:36, Steven D'Aprano  
wrote:

On Wed, 8 Apr 2015 12:36 am, jonas.thornv...@gmail.com wrote:

Bullshit declare two integers in any language one 7 and one 4 and then
write x=7+4; if you find a programming language where that does not yield
11 tell me.


In Forth, you can set the base to any arbitrary integer (within reason).

[...snip...]

In dc also (UNIX's reverse polish arbitrary precision "decimal calculator").  
You can set the input and output representation bases, and proceed without 
leading base indicators.


Cheers,
Cameron Simpson 

Hofstadter's Law: It always takes longer than you expect, even when you take
into account Hofstadter's Law.
- Douglas Hosfstadter, Godel, Escher, Bach: an Eternal Golden Braid
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Steven D'Aprano
On Wed, 8 Apr 2015 01:43 am, jonas.thornv...@gmail.com wrote:

> No that is not what i am saying, i am saying if you do operations on two
> integers the machine will assume base 10.


We understand what you are saying. You are simply WRONG.

There hasn't been a machine in common use that used other than binary for
integers for probably forty years now, and there has *never* been a PC that
has used other than binary for integers. When you write 12345 as an integer
in a programming language, it is NOT stored internally as five decimal
digits 1 2 3 4 5 in *nearly all languages*. There might be one or two
exceptions, e.g. Hypertalk would store it as a string of bytes 0x3132333435
in hexadecimal, or in binary 001100010011001000110011001101110101.

(As you can guess, Hypertalk is not the most efficient of languages.)

But most languages will store the decimal int 12345 in binary:

001100111001  # 16 bit word size

001100111001  # 32 bit word size

(Ignoring Big Endian/Little Endian issues -- some machines store the bytes
the other way around.)

The fact is computer languages automatically convert source code from
(usually) decimal base to whatever their internal storage format uses,
which is normally base 2. They don't work in decimal, using the same
decimal routines you learned in school.



-- 
Steven

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Steven D'Aprano
On Wed, 8 Apr 2015 12:32 am, Ian Kelly wrote:

> On average, a random Oracle with a search space of 100 will need
> 100 guesses.

Surely on average it will only take 50 guesses?

Best case is that it gets lucky the first time (1 guess). Worst case is that
it guesses every wrong answer until there is only one answer it hasn't
given, which is right (100 guesses). I assume that the Oracle is smart
enough to never repeat a guess.


-- 
Steven

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Steven D'Aprano
On Tue, 7 Apr 2015 07:44 pm, jonas.thornv...@gmail.com wrote:


> I want todo faster baseconversion for very big bases like base 1 000 000,
> so instead of adding up digits i search it.

What digits would you use for base one-million?

Base 2 uses 0 1.
Base 3 uses 0 1 2.
Base 10 uses 0 1 2 3 4 5 6 7 8 9.
Base 16 uses 0 1 2 3 4 5 6 7 8 9 A B C D E F.

Base one million uses what?

How would you write down 12345 in base one-million?



-- 
Steven

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


Re: Code critique please

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 4:43 PM,   wrote:
> def RenderByte(draw, byte, x, y):

Python function and method names customarily use the
lowercase_with_underscores style.

> blist = list(bin(byte).lstrip('0b')) # turn byte into list with 8 
> elements,

There's no guarantee that the resulting list will have 8 elements
here. The result of bin() will use the minimum number of digits needed
to represent the value, which has nothing to do with the size of a
byte. If you want exactly 8, use str.zfill to add zeroes.

Also, lstrip('0b') will remove *all* occurrences of the characters '0'
and 'b' from the left of the string, not just the exact substring
'0b'. So for example, bin(0).lstrip('0b') would return the empty
string since all the characters in the string are either '0' or 'b'.

That said, all this string manipulation to convert from an int to a
list of bits smells a bit funky to me. I'd probably write a generator
to yield the bits from the number. Something like:

def bits(number, length=None):
if length is None:
length = number.bit_length()
for i in range(length):
yield (number >> i) & 1

Now you can iterate directly over bits(byte, 8), or if you really want
a list then you can call list(bits(byte, 8)).

> c = 0# each representing one bit
> for bit in blist:
> if bit:
> draw.point((x + c, y), fcolor)
>
> c += 1

Instead of incrementing c on each loop, use enumerate.

for c, bit in enumerate(blist):

> return

Not needed if you're not returning a value. It's perfectly okay to
just let execution "fall off" the end of the function.

> # get out of here if EPD file not present
> if not os.path.isfile(epdfilename):
> print 'file not found: ' + edpfilename

Recommend using print's function syntax for forward compatibility with Python 3:

print('file not found: ' + edpfilename)

Also consider doing "from __future__ import print_function" at the top
of the file so that print really is a function, although it doesn't
matter in this case.

> xdim   = 1024
> ydim   = 1280
> header = 16
> black  = 0
> white  = 1
> bcolor = black
> fcolor = white

Constants, particularly global ones, are conventionally
UPPERCASE_WITH_UNDERSCORES.

> EPD_2_Image(epdfilename, imagefilename)

If you use the construct

if __name__ == '__main__':
EPD_2_Image(epdfilename, imagefilename)

then the function will automatically be called when the file is
executed as a script, but it will also let you import the file from
other modules and call it on your own terms, should you ever desire to
do that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Ian Kelly
On Tue, Apr 7, 2015 at 4:55 PM, Steven D'Aprano
 wrote:
> On Wed, 8 Apr 2015 12:32 am, Ian Kelly wrote:
>
>> On average, a random Oracle with a search space of 100 will need
>> 100 guesses.
>
> Surely on average it will only take 50 guesses?
>
> Best case is that it gets lucky the first time (1 guess). Worst case is that
> it guesses every wrong answer until there is only one answer it hasn't
> given, which is right (100 guesses). I assume that the Oracle is smart
> enough to never repeat a guess.

I didn't make that assumption. With replacement, the mean is 100,
per the binomial distribution.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Code critique please

2015-04-07 Thread Chris Kaynor
On Tue, Apr 7, 2015 at 3:43 PM,   wrote:
> I just wrote this bit (coming from Pascal) and am wondering how seasoned 
> Python programmers would have done the same? Anything terribly non-python?
>
> As always, thanks for all input.
>
> K
>
>
>
> """
>  Creates a PNG image from EPD file
> """
>
> import os, sys
> from PIL import Image, ImageFont, ImageDraw
>
> # 
> -
> def RenderByte(draw, byte, x, y):
>
> blist = list(bin(byte).lstrip('0b')) # turn byte into list with 8 
> elements,

A couple of comments on this line: lstrip strips based on characters,
and even without that, the 8 elements comment is not correct. bin()
only returns enough to hold the value without leading zeros, and the
lstrip will remove any leading zeros, even if it did produce them.

Additionally, if byte is outside the [0, 255] range, bin could produce
more than 8 elements. Your loop will work in any case, but it may
cause incorrect behavior, and in any case, the comment is wrong.

> c = 0# each representing one bit
> for bit in blist:
> if bit:
> draw.point((x + c, y), fcolor)
>
> c += 1

Rather than keeping a manual counter, this could be better written
using enumerate:

for c, bit in enumerate(blist):
if bit:
draw.point((x + c, y), fcolor)

> return

This return is unneeded. If a function falls off the end, it
implicitly has a bare "return" at its end. Note that a bare return (or
falling off the end) will cause the function to return None (all
functions have a return value).

>
> # 
> -
> def EPD_2_Image(edpfilename, imagefilename):
>
> # get out of here if EPD file not present
> if not os.path.isfile(epdfilename):
> print 'file not found: ' + edpfilename
> return
>
> # is this a valid EPD file?
> filesize = os.path.getsize(epdfilename)
> if (((xdim / 8) * ydim) + header) <> filesize:
> print 'incorrect file size: ' + edpfilename
> return

Both of these would probably be better as exceptions, rather than
prints. When running the function via a batch script, you can always
catch the exception and do something with it, while with a print, the
caller will have a hard time determining whether the function worked
or not. This could be important if you ever try to wrap this function
into a GUI (you may want a dialog rather than a command prompt
textural error, on stdout no less), or call the function with
batching, where you may want to report the failures via other means
(collect them all and include them in an e-mail report, for example).

For example, "raise OSError('file not found' + edpfilename)". Also, in
Python, the perfered dogma is "better to ask forgiveness than
permission" (aka, try the operation and let it fail if invalid),
rather than "look before you leap" (validate correct inputs, and fail
early). Basically, in this case, you could just remove the first check
(the second is probably worthwhile), and let the getsize fail if the
file does not exist.

Raising the exceptions will play better with batching (its easier to
detect errors and report them en-mass after processing). Avoiding LBYL
is generally useful for files in case other processes mess with them
after your check.

>
> # blow old destination file away
> if os.path.isfile(imagefilename):
> print 'deleting old dest. file: ' + imagefilename
> os.remove(imagefilename)

This is probably unneeded, and could cause issues with deleting the
file then failing out for various reasons. I generally prefer to leave
files intact until the last possible second. Thi sis nice if the code
fails for some reason.

>
> print 'processing...'
>
> # set up PIL objects
> img  = Image.new('1', (xdim, ydim), bcolor)   # '1' = Bi-tonal image
> draw = ImageDraw.Draw(img)
>
> # read entire EPD file into byte array (without the header)
> content = bytearray(open(epdfilename, 'rb').read())[16:]
>
> # image coord origin at top/left according to PIL documentation
> pos = 0
> for y in range(ydim):
> x = 0
> for byte in range(xdim / 8):   # 8 pixels 'stuffed' into one byte
> RenderByte(draw, content[pos], x, y)
> pos += 1
> x   += 8
>
> img.save(imagefilename)   # format is inferred from given extension
> print 'done.'
>
> return
> # 
> -
>
> xdim   = 1024
> ydim   = 1280
> header = 16
> black  = 0
> white  = 1
> bcolor = black
> fcolor = white

By convention, constants in Python are denoted by using all capital
letters with under scores.

>
> epdfilename   = 'c:\\temp\\drawtest2.epd'
> imagefilename = 'c:\\temp\\drawtest2.png'
>
> EPD_2_Image(epdfilename, imagefilename)
> --
> https://mail.python.org/mailman/listinfo/pyt

Re: Code critique please

2015-04-07 Thread Cameron Simpson

On 07Apr2015 15:43, kai.pet...@gmail.com  wrote:

I just wrote this bit (coming from Pascal) and am wondering how seasoned Python 
programmers would have done the same? Anything terribly non-python?

As always, thanks for all input.
K

"""
Creates a PNG image from EPD file
"""

import os, sys
from PIL import Image, ImageFont, ImageDraw

# -
def RenderByte(draw, byte, x, y):
   blist = list(bin(byte).lstrip('0b')) # turn byte into list with 8 elements,


Remark: .lstrip does not do what you think.
You want:

   blist = list(bin(byte)[2:]) # turn byte into list with 8 elements,

to skip over the leading "0b". Otherwise, with lstrip, consider what would 
happen with a low value byte, with multiple leading zeroes. (Actually, on 
reflection, you might get away with it - but probably not, and anyway would be 
fragile against changing the ordering of the bits.)


I'd be popping off the least or most siginificant bit myself with "&" and "<<" 
or ">>". It might be wordier, bit it would be more in keeping with the actual 
bitwise operations going on.



   c = 0# each representing one bit
   for bit in blist:
   if bit:
   draw.point((x + c, y), fcolor)
   c += 1


This might be more Pythonic written:

 for c, bit in enumerate(blist):

which will emit (0, b0), (1, b1) and so forth for bit 0, bit 1 etc (where bit 0 
is the leftmost from your list, etc). Avoids the "c = 0" and the "c += 1" and 
also makes your loop robust against adding control flows later which might skip 
the final "c += 1" at the end, even by accident.



   return


You generally do not need a trailing return with no value; it is implicit.


def EPD_2_Image(edpfilename, imagefilename):
   # get out of here if EPD file not present
   if not os.path.isfile(epdfilename):
   print 'file not found: ' + edpfilename
   return


Traditionally one would raise an exception instead of returning. Eg:

 if not os.path.isfile(epdfilename):
   raise ValueError("missing file: %r" % (epdfilename,))

and have the caller handle the issue. Similarly for all the other pre-checks 
below.


Also, it is normal for error messages to be directed to sys.stderr (this allows 
them to be logged independently of the program's normal output; for example the 
normal output might be sent to a file, but the error messages would continue to 
be displayed on screen). So were you to iussue a print statement (instead of an 
exception) you would write:


 print >>sys.stderr, 

or in Python 3:

 print(, file=sys.stderr)


   # is this a valid EPD file?
   filesize = os.path.getsize(epdfilename)
   if (((xdim / 8) * ydim) + header) <> filesize:
   print 'incorrect file size: ' + edpfilename
   return

   # blow old destination file away
   if os.path.isfile(imagefilename):
   print 'deleting old dest. file: ' + imagefilename
   os.remove(imagefilename)

   print 'processing...'

   # set up PIL objects
   img  = Image.new('1', (xdim, ydim), bcolor)   # '1' = Bi-tonal image
   draw = ImageDraw.Draw(img)

   # read entire EPD file into byte array (without the header)
   content = bytearray(open(epdfilename, 'rb').read())[16:]

   # image coord origin at top/left according to PIL documentation
   pos = 0
   for y in range(ydim):
   x = 0
   for byte in range(xdim / 8):   # 8 pixels 'stuffed' into one byte
   RenderByte(draw, content[pos], x, y)
   pos += 1
   x   += 8

   img.save(imagefilename)   # format is inferred from given extension
   print 'done.'

   return


Again, this "return" can be implicit.


# -

xdim   = 1024
ydim   = 1280
header = 16
black  = 0
white  = 1
bcolor = black
fcolor = white

epdfilename   = 'c:\\temp\\drawtest2.epd'
imagefilename = 'c:\\temp\\drawtest2.png'


Normally these values would be at the top of your program, and named in 
UPPER_CASE to indicate that they are like "constants" in other languages. So 
you might put this:


 XDIM   = 1024
 YDIM   = 1280
 HEADER_SIZE = 16
 BLACK  = 0
 WHITE  = 1
 BCOLOR = BLACK
 FCOLOR = WHITE

 EPD_FILENAME   = 'c:\\temp\\drawtest2.epd'
 IMAGE_FILENAME = 'c:\\temp\\drawtest2.png'

at the top of the script.

I notice you have a bare [16:] in your "content =" line. Should that not say 
"[HEADER_SIZE:]" ?



EPD_2_Image(epdfilename, imagefilename)


I tend to write things like this as thought they could become python modules 
for reuse. (Often they do; why write something twice?)


So the base of the script becomes like this:

if __name__ == '__main__':
 EPD_2_Image(EPD_FILENAME, IMAGE_FILENAME)

In this way, when you invoke the .py file directly __name__ is "__main__" and 
your function gets run. But it you move this all into a module which may be 
imported, __name__ will be the module name, an so not invoke the main function.  
The importing code can then do so as i

Re: Code critique please

2015-04-07 Thread kai . peters
On Tuesday, 7 April 2015 15:43:44 UTC-7, kai.p...@gmail.com  wrote:
> I just wrote this bit (coming from Pascal) and am wondering how seasoned 
> Python programmers would have done the same? Anything terribly non-python?
> 
> As always, thanks for all input.
> 
> K
> 
> 
> 
> """
>  Creates a PNG image from EPD file
> """
> 
> import os, sys
> from PIL import Image, ImageFont, ImageDraw
> 
> # 
> -
> def RenderByte(draw, byte, x, y):
> 
> blist = list(bin(byte).lstrip('0b')) # turn byte into list with 8 
> elements, 
> c = 0# each representing one bit
> for bit in blist:   
> if bit:
> draw.point((x + c, y), fcolor)
> 
> c += 1
> return
> 
> # 
> -
> def EPD_2_Image(edpfilename, imagefilename):
> 
> # get out of here if EPD file not present
> if not os.path.isfile(epdfilename):
> print 'file not found: ' + edpfilename
> return
> 
> # is this a valid EPD file?
> filesize = os.path.getsize(epdfilename)
> if (((xdim / 8) * ydim) + header) <> filesize:
> print 'incorrect file size: ' + edpfilename
> return
> 
> # blow old destination file away 
> if os.path.isfile(imagefilename):
> print 'deleting old dest. file: ' + imagefilename
> os.remove(imagefilename)
> 
> print 'processing...'
> 
> # set up PIL objects
> img  = Image.new('1', (xdim, ydim), bcolor)   # '1' = Bi-tonal image
> draw = ImageDraw.Draw(img)
> 
> # read entire EPD file into byte array (without the header)
> content = bytearray(open(epdfilename, 'rb').read())[16:] 
>  
> # image coord origin at top/left according to PIL documentation
> pos = 0
> for y in range(ydim): 
> x = 0
> for byte in range(xdim / 8):   # 8 pixels 'stuffed' into one byte
> RenderByte(draw, content[pos], x, y)
> pos += 1   
> x   += 8
> 
> img.save(imagefilename)   # format is inferred from given extension
> print 'done.'
> 
> return
> # 
> -
> 
> xdim   = 1024
> ydim   = 1280
> header = 16
> black  = 0
> white  = 1
> bcolor = black
> fcolor = white
> 
> epdfilename   = 'c:\\temp\\drawtest2.epd'
> imagefilename = 'c:\\temp\\drawtest2.png'
> 
> EPD_2_Image(epdfilename, imagefilename)


Thanks for taking the time to give such detailed suggestions - very much 
appreciated!

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Steven D'Aprano
On Wed, 8 Apr 2015 03:07 am, jonas.thornv...@gmail.com wrote:

> So you can tell me the first (higest) digit of the integer
>
2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490


First digit:
py> s
= 
'2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490'
py> s[0]
'2'


Highest digit:

py> max(s)
'9'


> Using base 429496729?

That makes no sense. With base 429496729 you need to have 429496729
different digits. Of course it is possible that, just by chance, you end up
with something that only includes the digits 0 through 9. Of course that is
possible, just like there are decimal numbers which only use digits 0
through 1, e.g. 10001.

If you want to go the other way, and convert s FROM decimal INTO base
429496729, you need to tell us what digits to use. You need 429496729
different digits.


> How long time did it take to find it?

A tiny fraction of a second.

py> from timeit import Timer
py> setup = "s
= 
'2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490'"
py> t = Timer("s[0]; max(s)", setup)
py> min(t.repeat())
7.158415079116821


That's just over 7 seconds to calculate both the first and the highest digit
one million times, or about 7 microseconds each time.




-- 
Steven

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


Re: Help with pipes, buffering and pseudoterminals

2015-04-07 Thread Gregory Ewing

Chris Angelico wrote:

Really? I can believe that stdout and stderr are initially duplicates,
but stdin as well? Isn't stdin opened for reading only, and
stdout/stderr for writing only?


It depends entirely on how the process that forked your
shell process set things up, but a quick experiment I
just did in a MacOSX terminal window suggests that it's
not really bothered about that distinction:

sh-3.2$ echo foo >&0
foo

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Dave Angel

On 04/07/2015 06:35 PM, jonas.thornv...@gmail.com wrote:

Den tisdag 7 april 2015 kl. 21:27:20 UTC+2 skrev Ben Bacarisse:

Ian Kelly  writes:


On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy  wrote:

On 4/7/2015 1:44 PM, Ian Kelly wrote:


def to_base(number, base):


... digits = []
... while number > 0:
... digits.append(number % base)
... number //= base
... return digits or [0]
...



to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
429496729)


[27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
79384857, 112868646, 221068759, 70871527, 416507001, 31]
About 15 microseconds.



% and probably // call divmod internally and toss one of the results.
Slightly faster (5.7 versus 6.1 microseconds on my machine) is


Not on my box.

$ python3 -m timeit -s "n = 100; x = 42" "n % x; n // x"
1000 loops, best of 3: 0.105 usec per loop
$ python3 -m timeit -s "n = 100; x = 42" "divmod(n,x)"
1000 loops, best of 3: 0.124 usec per loop


I get similar results, but the times switch over when n is large enough
to become a bignum.

--
Ben.


I am not sure you guys realised, that althoug the size of the factors to 
muliply expands according to base^(exp+1) for each digitplace the number of 
comparissons needed to reach the digit place (multiple of base^exp+1) is 
constant with my approach/method.



Baloney.

But even if it were true, a search is slower than a divide.



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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Steven D'Aprano
On Wed, 8 Apr 2015 03:44 am, Ian Kelly wrote:


to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
 429496729)
> [27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
> 79384857, 112868646, 221068759, 70871527, 416507001, 31]


They're not exactly *digits* though, are they? Without an easy to use set of
429496729 different symbols, the whole exercise is rather pointless. It's
not more compact: 97 decimal digits, versus 121 characters in the list
representation. 110 if you strip out the spaces between items. It's
certainly not more memory efficient: the long int 293...490 takes 56 bytes,
compared to 80 bytes for just the list, not including the memory used by
its 12 int items. (Results may vary in other versions of Python.) You can't
do arithmetic on it faster than Python's built-ins.

Besides, it isn't clear to me whether Jonas wants to convert decimal
293...490 *into* base 429496729 as you have done, or *base 429496729*
293...490 into decimal.



-- 
Steven

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Gregory Ewing

jonas.thornv...@gmail.com wrote:

No i don't i say the operations assume base ten other wise INT A=7,B=4
Calculate C=A+B would not yield 11 as an answer.


The answer, when converted to base 10, will still be
11 regardless of the base in which the arithmetic is
performed.

For example, in base 2:

A = 0111   (decimal 7)
B = 0100   (decimal 4)

C = 1011

Now convert binary 1011 to decimal and see what
you get.

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


Re: Code critique please

2015-04-07 Thread Mark Lawrence

On 07/04/2015 23:43, kai.pet...@gmail.com wrote:

I just wrote this bit (coming from Pascal) and am wondering how seasoned Python 
programmers would have done the same? Anything terribly non-python?

As always, thanks for all input.

import os, sys
from PIL import Image, ImageFont, ImageDraw



As you've had plenty of answers I'll just say that PIL is pretty old 
now.  Are you aware of the fork called Pillow? 
https://pillow.readthedocs.org/


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Gregory Ewing

Steven D'Aprano wrote:


What digits would you use for base one-million?


Interesting question. Unicode currently has about
75,000 CJK characters, so we would need to find about
12 more independently developed cultures with similar
writing systems to get enough characters. I suggest
revisiting the issue when interstellar travel and
exploration have been better developed.

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Steven D'Aprano
On Wed, 8 Apr 2015 10:38 am, Steven D'Aprano wrote:

> On Wed, 8 Apr 2015 03:44 am, Ian Kelly wrote:
> 
>
>
to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
> 429496729)
>> [27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
>> 79384857, 112868646, 221068759, 70871527, 416507001, 31]
> 
> 
> They're not exactly *digits* though, are they? 

Oh, I forgot... I think this is why Python long ints effectively uses a base
256 internal storage. If memory serves me correctly, internally a long int
is stored as an array of bytes using digits:

\x0 \x1 \x2 ... \xFF

(in decimal, 0 to 255). Each digit takes a single byte, so it's nicely
compact, and Python includes a bunch of fast algorithms for doing
arithmetic on these.

If the array is always a multiple of four bytes, then that is logically
equivalent to using base 4294967296 with 32-bit digits:

\x0\x0\x0\x0 \x0\x0\x0\x1 \x0\x0\x0\x2 ... \xFF\xFF\xFF\xFF

(in decimal, 0 to 4294967295). It's still fundamentally binary though, but I
suppose it's not entirely pointless to talk about base 2**32 or base 2**64
numbers, in the context of a high-performance Big Num implementation. But
it wouldn't be practical to use *arbitrary bases* up to 2**32 or 2**64, and
it certainly isn't practical to have human beings read or write numbers in
such large bases. 


-- 
Steven

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


Automate deployment of Python application from multiple VCS repositories

2015-04-07 Thread Ben Finney
Howdy all,

What tools are available to automate deployment of a Python application
comprising many discrete modules, spread across different code bases in
different VCS repositories?

My idea is to have a single definition (itself under VCS control) that
specifies VCS locations and branches, a hierarchy into which all the
modules fit, and a deployment host.

host foo:
repo ‘spam-common ’, branch ‘trunk’, at ‘./common/’
repo ‘beans ’, branch ‘version 6.1’, at ‘./’
repo ‘sausage ’, branch ‘trunk’, at ‘./third-party/sausage/’

host bar:
repo ‘spam-common ’, branch ‘maint’, at ‘./common/’
repo ‘beans ’, branch ‘version 7.0’, at ‘./’
repo ‘eggs ’, branch ‘master’, at ‘./third-party/eggs/’
repo ‘toast ’, branch ‘trunk’, at ‘./third-party/eggs/toast/’
repo ‘sausage ’, branch ‘version 1.4’, at ‘./third-party/sausage/’

The deployment tool, when told which host specification to use, then
gathers the code by exporting it from its disparate branches, fits it
into the directory hierarchy, and deploys that to the specified host.

The goal is to be able to have multiple host specifications, each of
which needs a different set of code repositories (and often different
branches within those repositories) to be built into the deployed
application.

What frameworks are there to do this for Python code?

-- 
 \   “Know what I hate most? Rhetorical questions.” —Henry N. Camp |
  `\   |
_o__)  |
Ben Finney

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Mark Lawrence

On 08/04/2015 01:59, Gregory Ewing wrote:

Steven D'Aprano wrote:


What digits would you use for base one-million?


Interesting question. Unicode currently has about
75,000 CJK characters, so we would need to find about
12 more independently developed cultures with similar
writing systems to get enough characters. I suggest
revisiting the issue when interstellar travel and
exploration have been better developed.



If it's available during PyCon can't we borrow the time machine? :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Chris Angelico
On Wed, Apr 8, 2015 at 8:51 AM, Steven D'Aprano
 wrote:
> There hasn't been a machine in common use that used other than binary for
> integers for probably forty years now, and there has *never* been a PC that
> has used other than binary for integers. When you write 12345 as an integer
> in a programming language, it is NOT stored internally as five decimal
> digits 1 2 3 4 5 in *nearly all languages*. There might be one or two
> exceptions, e.g. Hypertalk would store it as a string of bytes 0x3132333435
> in hexadecimal, or in binary 001100010011001000110011001101110101.
>
> (As you can guess, Hypertalk is not the most efficient of languages.)

FWIW, REXX does the same thing as Hypertalk - the integer 12345 and
the string "12345" are identical. If you add the string "1" and the
string "12345", you get the string "12346". (Concatenation is a
separate operation, and would result in the string "112345".) However,
Steven is still correct in that it is not stored as five decimal
digits; it's stored as five bytes in your system encoding. On my
systems, those were all ASCII-compatible, so it'd be 0x3132333435
(plus some metadata about string length and stuff, not germane to the
discussion), though I suspect that an EBCDIC system would store it as
0xF1F2F3F4F5 instead.

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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Chris Angelico
On Wed, Apr 8, 2015 at 8:57 AM, Steven D'Aprano
 wrote:
> On Tue, 7 Apr 2015 07:44 pm, jonas.thornv...@gmail.com wrote:
>
>
>> I want todo faster baseconversion for very big bases like base 1 000 000,
>> so instead of adding up digits i search it.
>
> What digits would you use for base one-million?
>
> Base 2 uses 0 1.
> Base 3 uses 0 1 2.
> Base 10 uses 0 1 2 3 4 5 6 7 8 9.
> Base 16 uses 0 1 2 3 4 5 6 7 8 9 A B C D E F.
>
> Base one million uses what?
>
> How would you write down 12345 in base one-million?

You could use base 1,114,112 fairly readily in any decent modern
programming language. That'll happily represent base one-million.

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


Re: Automate deployment of Python application from multiple VCS repositories

2015-04-07 Thread Paul Rubin
Ben Finney  writes:
> host foo:
> repo ‘spam-common ’, branch ‘trunk’, at ‘./common/’
> repo ‘beans ’, branch ‘version 6.1’, at ‘./’ ...
> What frameworks are there to do this for Python code?

I don't know what's out there for Python, but that reminds me a bit
of the Erlang tool "rebar": https://github.com/rebar/rebar

I half remember that there was a later alternative to rebar that had
similarities and maybe improvements.  

Anyway, these might be worth looking at if you're thinking of developing
a Python tool.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread Marko Rauhamaa
Steven D'Aprano :

> On Wed, 8 Apr 2015 03:07 am, jonas.thornv...@gmail.com wrote:
>> Using base 429496729?
>
> That makes no sense. With base 429496729 you need to have 429496729
> different digits.

You can use integers as digits. We already do that when we express times
and angles in base-60. I think even the Babylonians might have used such
structured digits.

>>> x = 
>>> 2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490
>>> while x >= 429496729: x //= 429496729
... 
>>> x
31


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


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den onsdag 8 april 2015 kl. 00:57:27 UTC+2 skrev Steven D'Aprano:
> On Tue, 7 Apr 2015 07:44 pm, jonas.thornv...@gmail.com wrote:
> 
> 
> > I want todo faster baseconversion for very big bases like base 1 000 000,
> > so instead of adding up digits i search it.
> 
> What digits would you use for base one-million?
> 
> Base 2 uses 0 1.
> Base 3 uses 0 1 2.
> Base 10 uses 0 1 2 3 4 5 6 7 8 9.
> Base 16 uses 0 1 2 3 4 5 6 7 8 9 A B C D E F.
> 
> Base one million uses what?
> 
> How would you write down 12345 in base one-million?
> 
> 
> 
> -- 
> Steven

Well digit places have to be comma separated i think i told you, in low bases 
we have unique digits so there is no problems write out numbers without 
separaation of digitplaces. But when the base is higher than the number of 
digits you have a choice to make. Either you invent a new numeral(number digit.

I think you realise that BB = 11,11

So your example would of course be ,12345

I hope you see A,B,C,D,E,F is only replacement for 10,11,12,13,14,15
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den onsdag 8 april 2015 kl. 03:00:12 UTC+2 skrev Gregory Ewing:
> Steven D'Aprano wrote:
> 
> > What digits would you use for base one-million?
> 
> Interesting question. Unicode currently has about
> 75,000 CJK characters, so we would need to find about
> 12 more independently developed cultures with similar
> writing systems to get enough characters. I suggest
> revisiting the issue when interstellar travel and
> exploration have been better developed.
> 
> -- 
> Greg

No need Greg it is an easy task creating visual interpretable symbols from low 
to high using lines in a point/pixel space. I could create the set in a day.

And if i use colour space it is even easier.

The hard part is making the point space visible and interpretabel without 
calculation and holding remainders in head. 

But then again when numbers have more than 5 digitplaces people tend to 
interpretate them digitwise anyway.

10010 is interpretated as a single digit by brain.
7582560 people mostly interpretate as 7 m 582 000 and 560.

You can tell how people group and think about numbers by having them reading up 
a very long telephone number.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best search algorithm to find condition within a range

2015-04-07 Thread jonas . thornvall
Den onsdag 8 april 2015 kl. 02:38:57 UTC+2 skrev Steven D'Aprano:
> On Wed, 8 Apr 2015 03:44 am, Ian Kelly wrote:
> 
> 
> to_base(2932903594368438384328325832983294832483258958495845849584958458435439543858588435856958650865490,
>  429496729)
> > [27626525, 286159541, 134919277, 305018215, 329341598, 48181777,
> > 79384857, 112868646, 221068759, 70871527, 416507001, 31]
> 
> 
> They're not exactly *digits* though, are they? Without an easy to use set of
> 429496729 different symbols, the whole exercise is rather pointless. It's
> not more compact: 97 decimal digits, versus 121 characters in the list
> representation. 110 if you strip out the spaces between items. It's
> certainly not more memory efficient: the long int 293...490 takes 56 bytes,
> compared to 80 bytes for just the list, not including the memory used by
> its 12 int items. (Results may vary in other versions of Python.) You can't
> do arithmetic on it faster than Python's built-ins.
> 
> Besides, it isn't clear to me whether Jonas wants to convert decimal
> 293...490 *into* base 429496729 as you have done, or *base 429496729*
> 293...490 into decimal.
> 
> 
> 
> -- 
> Steven

Well Steven you just draw a line under connecting them all, and now you are 
allowed to call whatever combination you write down a single digit.

And you have just created 429496729 unique symbols ;), in a pencil stroke.
I know at least one intergalactic poster that will be impressed ;)
-- 
https://mail.python.org/mailman/listinfo/python-list