Re: Leap year
On Saturday, September 27, 2014 9:21:15 AM UTC+5:30, Seymore4Head wrote:
> Still practicing. Since this is listed as a Pseudocode, I assume this
> is a good way to explain something. That means I can also assume my
> logic is fading with age.
> http://en.wikipedia.org/wiki/Leap_year#Algorithm
> Me trying to look at the algorithm, it would lead me to try something
> like:
> if year % 4 !=0:
> return False
> elif year % 100 !=0:
> return True
> elif year % 400 !=0:
> return False
> Since it is a practice problem I have the answer:
> def is_leap_year(year):
> return ((year % 4) == 0 and ((year % 100) != 0 or (year % 400) == 0))
> I didn't have any problem when I did this:
> if year % 400 == 0:
> print ("Not leap year")
> elif year % 100 == 0:
> print ("Leap year")
> elif year % 4 == 0:
> print ("Leap year")
> else:
> print ("Not leap year")
Python has an if-expression distinct from the if-statement.
However its confusing because its order is 'upside down'
So below I use C's if-expression a?b:c to state some 'laws' of programming and
leave it as an exercise to pythonify them
a?T:F ≡ a A
a?F:T ≡ not a B
a?T:b ≡ a or b C
a?b:F ≡ a and bD
if p: E
return x
else:
return y
≡
return (p ? x : y)
Likewise
if p F
print x
else
print y
≡
print (p ? x : y)
Now putting:
a ≜ y%4==0
b ≜ y%100!=0
c ≜ y%400 == 0
the expression that is the (given) answer is
a and (b or c)
Lets use the above laws to open it up
"by C"
a and (b ? T: c)
"by D"
a?(b?T:c):F
year%4==0 ? (y%100!=0 ? T: y%400==0) : F
--
Now lets take your version:
if year % 400 == 0:
print ("Not leap year")
elif year % 100 == 0:
print ("Leap year")
elif year % 4 == 0:
print ("Leap year")
else:
print ("Not leap year")
And now 'de-print' it [A good idea though I wont suggest it to you again!]
print (!c ? F : (b? T : (a? T : F)))
Forget about the print since its irrelevant and concentrate on
(!c ? F : (b? T : (a? T : F)))
"by A"
= (!c ? F : (b? T : a))
"by B"
= (c ? (b? T : a) : F)
"by D"
= (c and (b?T:a)
"by C"
= c and (b or a)
Lets re-substitute a,b,c
= y%400==0 and (y%100 !=0 or y%4 == 0)
which interpreted says that ONLY years divisible by 400 are leap
and not even all those!!
--
https://mail.python.org/mailman/listinfo/python-list
Obscuring Python source from end users
Hello list Python 3.4 applies. I have a project that involves distributing Python code to users in an organisation. Users do not interact directly with the Python code; they only know this project as an Excel add-in. Now, internal audit takes exception in some cases if users are able to see the source code. So I'm wondering if anyone has clever suggestions in this regard... My current plan is to modify the bdist_wheel setuptools extension so that it can produce distributions with only the .pyc files, laid out so that they will be importable in the normal way. This will be sufficient to satisfy internal audit, and will not negatively impact our users. However there are obvious downsides, including the overhead of maintaining separate wheels for different architectures and (in the future) Python versions. Not to mention that this plan seems to go against the grain of how Python wants to use byte code files... Is there a better solution? -- https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
On Mon, Sep 29, 2014 at 5:36 PM, wrote: > I have a project that involves distributing Python code to users in an > organisation. Users do not interact directly with the Python code; they only > know this project as an Excel add-in. > > Now, internal audit takes exception in some cases if users are able to see > the source code. The solution is to fix your internal audit. There's fundamentally no way to hide the source code, and it's going to add complexity. Demonstrate that it could take you a large number of man-hours and achieve little, and just declare that the source code IS what you want. Alternatively, you could do a source-level reformat that crunches everything down as much as possible, while still producing syntactically-identical source code. Remove all the comments, shorten local names to one letter, etc. That would result in something that, while still perfectly executable, won't be nearly as helpful. It wouldn't be nice readable source code, at least. Would your audit be satisfied with that? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
Thanks for the reply! I'm not concerned about hiding the source code in a fundamental way. The condition that needs to be satisfied is that independent validators (in the organisation) must not "have access" to the source code. Crunching the source is an interesting idea that could achieve that end, but it seems fraught with problems like maintaining consistency between renaming objects in a module and renaming where imports happen. -- https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
On Mon, 29 Sep 2014 00:36:47 -0700, norman.ives wrote: > Hello list > > Python 3.4 applies. > > I have a project that involves distributing Python code to users in an > organisation. Users do not interact directly with the Python code; they > only know this project as an Excel add-in. > > Now, internal audit takes exception in some cases if users are able to > see the source code. > > So I'm wondering if anyone has clever suggestions in this regard... > > My current plan is to modify the bdist_wheel setuptools extension so > that it can produce distributions with only the .pyc files, laid out so > that they will be importable in the normal way. This will be sufficient > to satisfy internal audit, and will not negatively impact our users. > > However there are obvious downsides, including the overhead of > maintaining separate wheels for different architectures and (in the > future) Python versions. Not to mention that this plan seems to go > against the grain of how Python wants to use byte code files... > > Is there a better solution? For an internal app. I would suggest it is only necessary to protect user- names & passwords to back end services (databases etc.). storing these in a separate file in an encrypted format should be enough to discourage internal users from digging deeper. This will not stop a determined hacker but neither will any other forms of obfuscation. -- new, adj.: Different color from previous model. -- https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
On Mon, Sep 29, 2014 at 6:41 PM, wrote: > Crunching the source is an interesting idea that could achieve that end, but > it seems fraught with problems like maintaining consistency between renaming > objects in a module and renaming where imports happen. > Here's a technique that you could use. Pick two prefixes, one for long names and one for short names, and maintain a translation table. So, for instance, you could have two source files like this: # file1.py # Do something with the length and the count def xx_some_func(length, cnt): # TODO: Implement me. pass # file2.py import file1 def xx_foo(lst, len, count): # Do something for every element in the list # where the something is blah blah blah for element in lst: file1.xx_some_func(len, count) And then your crunched files might be: # file1.py: def x_a(a,b): pass # file2.py import file1 def x_b(a,b,c): for d in a: file2.x_a(b,c) The translation is 100% mechanical: any place you find "xx_some_func", you replace it with "x_a". If you find a string that begins "xx_" and isn't in your translation table, you construct a new name (don't forget that you can use x_A as well as x_a) and add it to the table. It ought to be possible to do an AST reconstitution for at least part of this. I can hunt down some of my PEP 463 test code to help out with that. It should be possible to figure out what names are local, and then just use those. If this is of interest, I'll see what I can knock together. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Weird SSL problem
Hi!
I’m trying to access
https://stsadweb.one.microsoft.com/adfs/.well-known/openid-configuration
Doing it the simplest way I get the following:
>>> import urllib
>>> f =
>>> urllib.urlopen("https://stsadweb.one.microsoft.com/adfs/.well-known/openid-configuration";)
Traceback (most recent call last):
File "", line 1, in
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py",
line 87, in urlopen
return opener.open(url)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py",
line 208, in open
return getattr(self, name)(url)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py",
line 437, in open_https
h.endheaders(data)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 969, in endheaders
self._send_output(message_body)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 829, in _send_output
self.send(msg)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 791, in send
self.connect()
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
line 1176, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line
387, in wrap_socket
ciphers=ciphers)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line
143, in __init__
self.do_handshake()
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line
305, in do_handshake
self._sslobj.do_handshake()
IOError: [Errno socket error] [Errno 54] Connection reset by peer
>>> import ssl
>>> ssl.OPENSSL_VERSION
’OpenSSL 0.9.8za 5 Jun 2014'
Now, using Safari, or curl for that matter, from the same machine works without
a hitch.
The URL above is also the only URL I’ve encountered this problem with.
Anyone got an idea ?
— Roland
”Being able to think like a child is an important attribute of being an adult”
- Eddie Izzard
--
https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
On Mon, Sep 29, 2014 at 6:55 PM, Chris Angelico wrote:
> It ought to be possible to do an AST reconstitution for at least part
> of this. I can hunt down some of my PEP 463 test code to help out with
> that. It should be possible to figure out what names are local, and
> then just use those.
>
> If this is of interest, I'll see what I can knock together.
Actually, why reconstitute? The AST can be compiled.
Here's a Python cruncher/obscurer:
import ast, sys, os
# Note: If the file can't be parsed, this will raise SyntaxError
# (from the ast.parse() line).
def crunch(fn, outfn):
with open(fn, "rb") as f:
data = f.read()
tree = ast.parse(data)
os.makedirs(os.path.split(outfn)[0], exist_ok=True)
with open(outfn, "w") as f:
print("from ast import *", file=f)
print("_code = "+ast.dump(tree), file=f)
print("fix_missing_locations(_code)", file=f)
print("[globals().__delitem__(_) for _ in dir() if _[0]!='_']", file=f)
print("exec(compile(_code,__name__,'exec'))", file=f)
if __name__ == "__main__":
for fn in sys.argv[1:]:
outfn = "crunched/" + fn
crunch(fn, outfn)
print("Crunched", fn, "to", outfn)
The resulting files should work just the same as the original ones,
but will be virtually unreadable. This is still only obscurity,
though; the only information actually removed is formatting and
comments, not even names. But you could easily add an ast.walk() in
there, just after the ast.parse(), and do whatever transformations you
want.
Note that unlike with JavaScript crunching, this won't shrink the
files - in fact, it's usually going to expand them. They'll probably
also take longer to load. There is no benefit other than the
obscurity.
Run this over some of your files, then see if your auditors are happy.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
ANN: eGenix PyCon UK 2014 Talks & Videos
ANNOUNCING
eGenix PyCon UK 2014 Talks & Videos
This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/PyCon-UK-2014-Presentations.html
We have just published the talk slides and videos of our PyCon UK 2014
presentations.
The PyCon UK Conference is the premier conference for Python users and
developers in the UK. This year it was held from September 19-22 in
Coventry, UK.
EGENIX TALKS AT PYCON UK 2014
At this year's PyCon UK, Marc-André Lemburg, CEO of eGenix, gave the
following talks at the conference. The presentations are available for
viewing and download from our Presentations and Talks section:
http://www.egenix.com/library/presentations/
When performance matters ...
Simple idioms you can use to make your Python code run faster and
use less memory.
Python applications sometimes need all the performance they can
get. Think of e.g. web, REST or RPC servers. There are several ways
to address this: scale up by using more processes, use Cython, use
PyPy, rewrite parts in C, etc.
However, there are also quite a few things that can be done directly
in Python. This talk goes through a number of examples and show
cases how sticking to a few idioms can easily enhance the
performance of your existing applications without having to revert
to more complex optimization strategies.
The talk was complemented with a lightning talk titled "Pythons and
Flies", which addresses a memory performance idiom and answers one
of the audience questions raised in the above talk.
Talk video and slides:
http://www.egenix.com/library/presentations/PyCon-UK-2014-When-performance-matters/
Python Web Installer
Installing Python packages is usually done with one of the available
package installation systems, e.g. pip, easy_install, zc.buildout,
or manually by running "python setup.py install" in a package
distribution directory.
These systems work fine as long as you have Python-only
packages. For packages that contain binaries, such as Python C
extensions or other platform dependent code, the situation is a lot
less bright.
In this talk, we present a new web installer system that we're
currently developing to overcome these limitations.
The system combines the dynamic Python installation interface
supported by all installers ("python setup.py install"), with a web
installer which automatically selects, downloads, verifies and
installs the binary package for your platform.
Talk video and slides:
http://www.egenix.com/library/presentations/PyCon-UK-2014-Python-Web-Installer/
If you are interested in learning more about these idioms and
techniques, eGenix now offers Python project coaching and consulting
services to give your project teams advice on how to achieve best
performance and efficiency with Python:
http://www.egenix.com/services/coaching/
Please contact our eGenix Sales Team for information: [email protected].
INFORMATION
About Python (http://www.python.org/):
Python is an object-oriented Open Source programming language
which runs on all modern platforms. By integrating ease-of-use,
clarity in coding, enterprise application connectivity and rapid
application design, Python establishes an ideal programming
platform for today's IT challenges.
About eGenix (http://www.egenix.com/):
eGenix is a software project, consulting and product company
focusing on expert project services and professional quality
products for companies, Python users and developers.
Enjoy,
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Sep 29 2014)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
2014-09-30: Python Meeting Duesseldorf ... tomorrow
: Try our mxODBC.Connect Python Database Interface for free ! ::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
--
https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
[email protected] wrote: > Hello list > > Python 3.4 applies. > > I have a project that involves distributing Python code to users in an > organisation. Users do not interact directly with the Python code; they > only know this project as an Excel add-in. > > Now, internal audit takes exception in some cases if users are able to see > the source code. You have my sympathy. > So I'm wondering if anyone has clever suggestions in this regard... Yes. Distribute the pyc files only. That is the canonical Python answer to the problem of not distributing source code. You may need a tiny "driver" script (or perhaps not), if you do it will be something as minor as: import module_where_all_the_work_is_really_done as module module.main() depending on how the Excel add-in system works. > My current plan is to modify the bdist_wheel setuptools extension so that > it can produce distributions with only the .pyc files, laid out so that > they will be importable in the normal way. This will be sufficient to > satisfy internal audit, and will not negatively impact our users. Sounds good to me. Do you know about the compileall.py script/module in the standard library? > However there are obvious downsides, including the overhead of maintaining > separate wheels for different architectures and (in the future) Python > versions. Not to mention that this plan seems to go against the grain of > how Python wants to use byte code files... Well, yes, it does go against the grain, but byte-code only distributions are officially supported. Occasionally people have made requests to simplify the import system by dropping support for .pyc only imports, but Python's creator Guido van Rossum has made it clear that as alien as such a thing is to the open source community, Python is going to allow it. Another possibility is to distribute your modules inside a zip file. See here: https://mail.python.org/pipermail/python-list/2014-July/675506.html Such zip files are not just runnable, but also importable. Depending on your Excel requirements, you might need a tiny driver script as above. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Teaching Python
Hi, my 11 years old son and his classmate told me, that they would like to learn Python. They did some programming in Logo and turtle graphics, bat not too much. Doesn anybody has an idea how to start? -- Urbán Gábor Linux is like a wigwam: no Gates, no Windows and an Apache inside. -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
On Mon, Sep 29, 2014 at 11:18 PM, Gabor Urban wrote: > my 11 years old son and his classmate told me, that they would like to learn > Python. They did some programming in Logo and turtle graphics, bat not too > much. > > Doesn anybody has an idea how to start? Right here: https://docs.python.org/3/tutorial/ There are other tutorials on the web, too. I strongly recommend starting with Python 3. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
Gabor Urban wrote: > Hi, > > my 11 years old son and his classmate told me, that they would like to > learn Python. They did some programming in Logo and turtle graphics, bat > not too much. > > Doesn anybody has an idea how to start? The Internet is a big place, I always start by searching :-) https://duckduckgo.com/html/?q=python+tutorial+for+kids https://duckduckgo.com/html/?q=python+turtle+graphics https://startpage.com/do/search?q=python+programming+for+children Are you looking for instruction on how you can teach them, or for self-directed learning they can do on their own? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
On Monday, September 29, 2014 6:59:10 PM UTC+5:30, Chris Angelico wrote: > On Mon, Sep 29, 2014 at 11:18 PM, Gabor Urban wrote: > > my 11 years old son and his classmate told me, that they would like to learn > > Python. They did some programming in Logo and turtle graphics, bat not too > > much. > > Doesn anybody has an idea how to start? > Right here: > https://docs.python.org/3/tutorial/ The official tutorial for an 11 year old?? I dont think so... > There are other tutorials on the web, too. I strongly recommend > starting with Python 3. There's the official turtle graphics Then there's this https://code.google.com/p/pynguin/ Though I guess just as the official tutorial is too adult for an 11 year old, turtle graphics may be too childish. You know your son better than we do: What excites him? Bores him? If you tell us then appropriate suggestions may follow -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
On Mon, Sep 29, 2014 at 11:38 PM, Rustom Mody wrote: >> https://docs.python.org/3/tutorial/ > > The official tutorial for an 11 year old?? I dont think so... I don't see why not, to be honest. Not a lot of difference between his 11yo son and my 12yo sister, and I just pointed her at the tutorial and Idle's interactive mode and set her going. But the father is the best one to judge that; if the boys have dabbled in programming already, he and/or they will know if the tutorial's aimed too high for them. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: trouble building data structure
David Alban wrote:
> greetings,
>
> i'm writing a program to scan a data file. from each line of the data
> file
> i'd like to add something like below to a dictionary. my perl background
> makes me want python to autovivify, but when i do:
>
> file_data = {}
>
> [... as i loop through lines in the file ...]
>
> file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, }
>
> i get:
>
> Traceback (most recent call last):
> File "foo.py", line 45, in
> file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, }
> KeyError: '91b152ce64af8af91dfe275575a20489'
>
> what is the pythonic way to build my "file_data" data structure above that
> has the above structure?
Others have suggested using a defaultdict, but here's an older solution: use
the setdefault method on regular dicts.
This fails:
py> file_data = {}
py> file_data[1234][23] = {'spam': 1, 'eggs': 2}
Traceback (most recent call last):
File "", line 1, in
KeyError: 1234
But this succeeds:
py> file_data.setdefault(1234, {})[23] = {'spam': 1, 'eggs': 2}
py> file_data.setdefault(5678, {})[42] = {'spam': 3, 'cheese': 1}
py> file_data
{1234: {23: {'spam': 1, 'eggs': 2}}, 5678: {42: {'spam': 3, 'cheese': 1}}}
Whether you prefer to use setdefault, or a defaultdict, is a matter of
taste.
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list
Re: Storage Cost Calculation
Abohfu venant zinkeng gmail.com> writes: > > > > > Hard drives have been the secondary storage of choice on computers for many years. They have improved in speed, in capacity, and in cost for over 50 years. It's interesting to look at how the prices have dropped, or, conversely, how much storage your money will buy now as compared to many years ago. This improvement is an example of Moore's Law > This site was written by a person (in 2009) who had considered this amazing trend. He collected a lot of data about hard drive capacity and price. The formula he extrapolated by using the data he found iscost per gigabyte = 10-0.2502(year-1980) + 6.304where year is the year for which the extrapolated cost was desired. This formula is based on data from 1980 to 2010.Your program should develop a table of costs, based on the user's inputs of the starting and ending years and the formula. The table should produce columns as seen below, The column Year is the year, starting at the point the user says to start at, and going to the ending year, stopping there. The size of the step in the table is also specified by the user. The user inputs are all integers. Your program can assume that. NOTE: The "ending year, stopping there" phrase is a bit ambiguous. If you want to use the ending year as the stop value in a range function, that is fine. If you want to add one to the ending year and use that as the stop value, that is also ok. In the tables below, end year plus one was used. Tab characters can be used. > Sample Run:Big Blue Hard Drive Storage Cost > > Enter the starting year: 1992 > Enter the ending year: 2015 > What step size for the table? 4 > > Hard Drive Storage Costs Table > > Start Year = 1992 > End Year = 2015 > >Year Cost Per Gigabyte ($) > >1992 2002.627 >1996 199.894 >2000 19.953 >2004 1.992 >2008 0.199 >2012 0.02 > Another Run:Big Blue Hard Drive Storage Cost > > Enter the starting year: 1998 > Enter the ending year: 2010 > What step size for the table? 2 > > Hard Drive Storage Costs Table > > Start Year = 1998 > End Year = 2010 > >Year Cost Per Gigabyte ($) > >1998 63.154 >2000 19.953 >2002 6.304 >2004 1.992 >2006 0.629 >2008 0.199 >2010 0.063 > QUESTION > Could someone help me with a design and a python program to implement that design to solve the above problem? > > > > > > > > Hard drives have been the secondary storage of choice on computers for many years. They have improved in speed, in capacity, and in cost for over 50 years. It's interesting to look at how the prices have dropped, or, conversely, how much storage your money will buy now as compared to many years ago. This improvement is an example of http://en.wikipedia.org/wiki/Moore%27s_law";>Moore's Law > http://www.mkomo.com/cost-per-gigabyte";>This site was written by a person (in 2009) who had considered this amazing trend. He collected a lot of data about hard drive capacity and price. The formula he extrapolated by using the data he found iscost per gigabyte = 10-0.2502(year-1980) + 6.304where year is the year for which the extrapolated cost was desired. This formula is based on data from 1980 to 2010.Your program should develop a table of costs, based on the user's inputs of the starting and ending years and the formula. The table should produce columns as seen below, The column Year is the year, starting at the point the user says to start at, and going to the ending year, stopping there. The size of the step in the table is also specified by the user. The user inputs are all integers. Your program can assume that. NOTE: The "ending year, stopping there" phrase is a bit ambiguous. If you want to use the ending year as the stop value in a range function, that is fine. If you want to add one to the ending year and use that as the stop value, that is also ok. In the tables below, end year plus one was used. Tab characters can be used. > Sample Run:Big Blue Hard Drive Storage Cost > > Enter the starting year: 1992 > Enter the ending year: 2015 > What step size for the table? 4 > > Hard Drive Storage Costs Table > > Start Year = 1992 > End Year = 2015 > >Year Cost Per Gigabyte ($) > >1992 2002.627 >1996 199.894 >2000 19.953 >2004 1.992 >2008 0.199 >2012 0.02 > Another Run:Big Blue Hard Drive Storage Cost > > Enter the starting year: 1998 > Enter the ending year: 2010 > What step size for the table? 2 > > Hard Drive Storage Costs Table > > Start Year = 1998 > End Year = 2010 > >Year Cost Per Gigabyte ($) > >1998
Re: Storage Cost Calculation
On Sun, 28 Sep 2014 20:07:31 +, Duncan Booth wrote: > Later on the B+ had 64k of RAM and the B+128 had 128k of RAM and in each > case the additional RAM was paged in as necessary but I don't think the > RAM in the B was ever expandable. You could get various expansions to page multiple roms, I had a machine at one point with 15 multiple internally and a zif socket on top. I think there was a board that sat across the 4 paged ROM sockets which then had a cable to another board with 16 sockets on it, and one of the 16 sockets came through the case in a ZIF. Aries or Dabs or Watford Electronics I expect. I also remember soldering switches to TEAC drives from RS to make them 40 / 80 track switchable. Duncan, your name looks mighty familiar . Do you know a Judith? -- Denis McMahon, [email protected] -- https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
Steven D'Aprano wrote: > Another possibility is to distribute your modules inside a zip file. See > here: > > https://mail.python.org/pipermail/python-list/2014-July/675506.html > > Such zip files are not just runnable, but also importable. Depending on your > Excel requirements, you might need a tiny driver script as above. It should also be possible to temper with the zipimport module to allow a 'scrambled' zip file. That makes it harder for users to access the code by unpacking the zip file. py2exe will collect pyc files into a single zip file and import that. It does not need a driver script because it embeds the Python interpreter in an executable. Yet another option is to compile the Python code with Cython and distribute everything as compiled pyd files. Sturla -- https://mail.python.org/mailman/listinfo/python-list
Re: Obscuring Python source from end users
Chris Angelico wrote: >> I have a project that involves distributing Python code to users in an >> organisation. Users do not interact directly with the Python code; they >> only know this project as an Excel add-in. >> >> Now, internal audit takes exception in some cases if users are able to >> see the source code. > > The solution is to fix your internal audit. +1 -- https://mail.python.org/mailman/listinfo/python-list
Re: trouble building data structure
On Mon, Sep 29, 2014 at 7:52 AM, Steven D'Aprano
wrote:
> Whether you prefer to use setdefault, or a defaultdict, is a matter of
> taste.
There is potentially a significant difference in performance -- with
setdefault, the subordinate data structure is created on every call to
be passed into setdefault, only to be discarded if the key already
exists. With defaultdict, the subordinate data structure is only
created when needed. Dicts are pretty cheap to construct though, and
this is probably not worth fretting over until profiling shows it to
be a problem.
On the other hand, it's easier to nest setdefaults arbitrarily deep
than it is for defaultdicts. This is because defaultdict suffers from
a design flaw -- defaultdict should be a function that returns a class
(like namedtuple), not a class itself. Fortunately that's easily fixable:
_DEFAULT_DICT_CACHE = {}
def defaultdict(callable):
try:
return _DEFAULT_DICT_CACHE[callable]
except KeyError:
class _defaultdict(dict):
def __missing__(self, key):
self[key] = value = self._callable()
return value
_DEFAULT_DICT_CACHE[callable] = _defaultdict
return _defaultdict
A downside is that it would take some extra work to make this picklable.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
On Mon, 29 Sep 2014 15:18:31 +0200, Gabor Urban wrote: >Hi, > >my 11 years old son and his classmate told me, that they would like to >learn Python. They did some programming in Logo and turtle graphics, bat >not too much. > >Doesn anybody has an idea how to start? I ordered this book from the library a few weeks ago. It just came in yesterday. Python for kids. Jason R Briggs This was also a good page for starters. http://www.practicepython.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
On 29 September 2014 14:18:31 BST, Gabor Urban wrote: >my 11 years old son and his classmate told me, that they would like to >learn Python. They did some programming in Logo and turtle graphics, >bat >not too much. > >Doesn anybody has an idea how to start? "How to Think Like a Computer Scientist - Learning with Python 3": http://openbookproject.net/thinkcs/python/english3e/ If you're after a printed book, the original (I believe) author's current version is here: http://www.greenteapress.com/thinkpython/thinkpython.html Simon -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
I am actually teaching Python as a side job. My students have ranged from eighth graders, up to a Silicon Valley hardware engineer who had no coding experience, but who needed to do some test engineering. My wife is an elementary school teacher. We occasionally talk about age-appropriate learning, and pedagogical strategies. I once watched a research biologist try to explain restriction enzymes to my sixth-grade son. It was painful to watch. Sure, my son is a smart kid, but there was no way he was going to understand what she was talking about without some background. For my younger Python students, I interact with them directly, sitting by their side while they type. Initially, I do not ask them to read any computer documentation. It's too difficult for them, even the official Python tutorial. The tutorial is aimed at an adult reader who has at least a little computer experience -- and sometimes, quite a lot. Just read Chapter 1. Imagine that you're 14 years old, reading that. Even if you have already programmed in one of the languages aimed at children, like Scratch, you will be in way over your head. Now, even though I think that the Python tutorial is too hard for young students to read, I do cover much of the MATERIAL in that tutorial, and in approximately the same order. I sit the student down in front of the interpreter, explain what an interpreter is, and then have them type simple mathematical expressions. I introduce variable names, and then strings, and lists. This is, more or less, the material in Chapter 3 of the tutorial -- although lists are not discussed until Chapter 5. Next, I introduce the idea of a program file, and have them start working with an editor. That's not in the tutorial at all. I introduce the print() function (briefly mentioned in Chapter 3), and the for statement (Section 4.2). Once you introduce the for statement, you need to explain code blocks, the use of a colon at the end of a line, and the use of indentation. This is enough information to get the student to write short programs. I start with single loops. Then, I have the student write a multiplication table program. Getting the student to grasp the idea of a loop inside a loop can sometimes be challenging. The next three things that I teach are the if statement (Section 4.1), the input() function (which appears in Chapter 4 of the tutorial, without any introduction or explanation), and string concatenation using the + operator. This is enough to get the student to write a program which accepts an input string, and prints out an alphabetized version of that string. I do not show the student the sorted() function until after they write the program with what they know! Typically, I move on to the range() function and slicing operations next. But unless you are working with very bright kids, that should be enough to keep them busy for a while. :^) -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching Python
On 9/29/2014 9:18 AM, Gabor Urban wrote: Hi, my 11 years old son and his classmate told me, that they would like to learn Python. They did some programming in Logo and turtle graphics, bat not too much. Doesn anybody has an idea how to start? Python has a turtle module, so they can continue where they left off. The turtledemo package has about 20 example programs and shows code in one pane beside a turtle canvas in another. The new 3.4.2 (release candidate now, final in a week or two) has several turtle and turtledemo fixes. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Weird SSL problem
In article ,
Roland Hedberg wrote:
> Hi!
>
> I¹m trying to access
> https://stsadweb.one.microsoft.com/adfs/.well-known/openid-configuration
>
> Doing it the simplest way I get the following:
>
> >>> import urllib
> >>> f =
> >>> urllib.urlopen("https://stsadweb.one.microsoft.com/adfs/.well-known/openid
> >>> -configuration")
> Traceback (most recent call last):
> File "", line 1, in
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py",
>line 87, in urlopen
> return opener.open(url)
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py",
>line 208, in open
> return getattr(self, name)(url)
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py",
>line 437, in open_https
> h.endheaders(data)
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py"
> , line 969, in endheaders
> self._send_output(message_body)
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py"
> , line 829, in _send_output
> self.send(msg)
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py"
> , line 791, in send
> self.connect()
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py"
> , line 1176, in connect
> self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
> line 387, in wrap_socket
> ciphers=ciphers)
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
> line 143, in __init__
> self.do_handshake()
> File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
> line 305, in do_handshake
> self._sslobj.do_handshake()
> IOError: [Errno socket error] [Errno 54] Connection reset by peer
> >>> import ssl
> >>> ssl.OPENSSL_VERSION
> ¹OpenSSL 0.9.8za 5 Jun 2014'
>
> Now, using Safari, or curl for that matter, from the same machine works
> without a hitch.
>
> The URL above is also the only URL I¹ve encountered this problem with.
>
> Anyone got an idea ?
I believe the problem is that the connection is protected by a
multi-hostname server certificate and Python 2's urllib (and underlying
httplib and ssl modules) do not support SNI extensions to TLS. The
request above works fine with Python 3 (which has supported client-side
SNI since Python 3.2). See http://bugs.python.org/issue5639 for more
discussion of the matter. If Python 3 is not an option for you, the
requests package available via PyPI should help.
--
Ned Deily,
[email protected]
--
https://mail.python.org/mailman/listinfo/python-list
JSON-encoding very long iterators
I would like to add the ability to JSONEncode large iterators. Right now there is no way to do this without modifying the code. The JSONEncoder.default() doc string suggests to do this: For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) but this method requires the whole serialized object to fit in memory and it's a good chance that your iterator is an iterator to save on memory in the first place. By changing the code to accept iterators it is then possible to stream json as I did here: http://stackoverflow.com/a/26094558/289240 This would ideal if it were included in the standard library. Is there any reason why it shouldn't be? -- https://mail.python.org/mailman/listinfo/python-list
Re: JSON-encoding very long iterators
On Mon, Sep 29, 2014 at 7:19 PM, wrote: > I would like to add the ability to JSONEncode large iterators. Right now > there is no way to do this without modifying the code. > > The JSONEncoder.default() doc string suggests to do this: > For example, to support arbitrary iterators, you could > implement default like this:: > def default(self, o): > try: > iterable = iter(o) > except TypeError: > pass > else: > return list(iterable) > # Let the base class default method raise the TypeError > return JSONEncoder.default(self, o) > > but this method requires the whole serialized object to fit in memory and > it's a good chance that your iterator is an iterator to save on memory in the > first place. > > By changing the code to accept iterators it is then possible to stream json > as I did here: > http://stackoverflow.com/a/26094558/289240 > > This would ideal if it were included in the standard library. Is there any > reason why it shouldn't be? This would cause things that aren't lists to be encoded as lists. Sometimes that may be desirable, but in general if e.g. a file object sneaks its way into your JSON encode call, it is more likely correct to raise an error than to silently encode the file as if it were a list of strings. So it should not be the default behavior. That said, it sounds like it could be made easier to enable streaming from iterators as an option for those cases where it's desired. -- https://mail.python.org/mailman/listinfo/python-list
