Re: Cutting a deck of cards
> Why on Earth would you want to? "Cutting" a deck makes no sense in > software. Randomize the deck properly (Google "Fisher-Yates") and start > dealing. Cutting the deck will not make it any more random, and in fact > will probably make it worse depending on how you choose the cutpoint. > > The purpose of "cutting" cards is to make it more difficult for human > dealers to stack a deck. Simulating it in software makes no more sense than > simulating the cigars you smoke while playing. > > Perhaps the OP wanted to study the efficiency and affect of a real-world shuffling algorithm :-p Maybe he was designing a probabilistic magic trick and needed to evaluate how a cut would modify the outcome of a particular stack. Maybe it was a school assignment. Who knows? (But yeah if the purpose was for pure randomization then there's no real point.) There could be a lot of legitimate reasons though. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Begin Web Development with Python ?
> I have learnt python and used it for various purposes for scietific > computing using sage and GUI development using Tkinter and lots more. I > want to start web development using python My goal is to learn the web > development in python from the basic level and understand the big web > development projects like Django , MoinMoin Wiki , Plone and network > programming further with twisted. > > I have found Web2Py to be an easy library to quickly use and develop the > web application. Is there any other library to start my development with. > and > does my plan of learning Web2Py is good for Web development and getting > involved in the big projects like Django , MoinMoin Wiki , Plone. > > Each web framework is kind of its own niche. I wouldn't learn one for the purpose of learning another. For example to use Django effectively requires knowledge specific to Django. Aside from some casual similarities between various web frameworks they're all pretty different. If you feel comfortable with web2Py and it does what you need - use the heck out of it! I've heard good things about Web2Py but not used it myself. I used Django for a while but found it to usually be over complicated for most of my needs. In other areas it wasn't advanced enough. (For instance I had an unusual requirement once for composite foreign key support, something Django's ORM couldn't handle at the time. I also disliked the template language. By the time I replaced the ORM and the template language the only thing I was really using was the URL routing so I jumped ship. (Don't get me wrong, I know people who love Django - just not me.) Cherrypy is neat but I found it to be more spartan than I prefer. I've since settled on Flask with SQLAlchemy and am liking it very much. It's a nice middle ground. It also has extensive documentation and example files too. Of course it really helped that I already knew SQLAlchemy, thus pairing it with Flask was cake. While not a web framework, learning SQLAlchemy is useful in its own right because it can be used in a wide variety of projects and is used by some web frameworks. It's also an excellent package that lets you use most of the features of your specific database backend. For web apps staying abstract is usually a good idea, but honestly how often do you change SQL backends? I think I've done it once in my career. I've found the advantage of using database specific features generally outweighs the drawbacks. This is especially true if you have more than one client/website accessing the same database. SQLAlchemy gets me the best of both worlds. I can define check constraints and enumerations and all the other goodies and have them match between database clients. If you don't already know this from scientific computing, learning some raw SQL is quite useful too! Sometimes you need a non-trivial query. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Begin Web Development with Python ?
> > I have learnt python and used it for various purposes for scietific > > computing using sage and GUI development using Tkinter and lots more. I > > want to start web development using python My goal is to learn the web > > development in python from the basic level and understand the big web > > development projects like Django , MoinMoin Wiki , Plone and network > > programming further with twisted. > > > > I have found Web2Py to be an easy library to quickly use and develop the > > web application. Is there any other library to start my development with. > > and > > does my plan of learning Web2Py is good for Web development and getting > > involved in the big projects like Django , MoinMoin Wiki , Plone. > > > > Modulok suggested using ORM software. ORM should not really be needed if > you are aiming at scientific content for your application, you should > be fine with straight SQL (many consider ORM a hindrance rather than > help for any project [1], [2]). But if you do find the need for ORM > then SQLAlchemy is very good and is considered pretty much a de facto > standard in the Python world. > > Good luck, and I'm sure comp.lang.python posters will be happy to help > you with any problems you come across! > > [1] https://en.wikipedia.org/wiki/Object-relational_mapping#Controversy > [2] http://goo.gl/ECNSp > > > In SQLalchemy you can use straight SQL, or a database abstraction, or a full ORM depending on your needs. The full ORM scared me at first. It was over-complicated nonsense, black magic and I already had a background in SQL on a console. I knew the exact queries I wanted. I didn't need this technical obfuscation wedged between me and greatness. However the more I used it the more I started to like it. (Slowly!) It's kind of an acquired taste. It's not perfect for everything, but it's usually quite useful once you become comfortable with it. Even so there are some valid points made against them. The nice part about SQLalchemy over most other "orm" packages is it doesn't really care how high or low level you interact with your data. It supports them all. You can do a raw SQL query on a cursor if you want. If you need more, you can use the database abstraction. Or more still is setting up a full ORM. You're never locked into anything. The down side to SQLalchemy however it is a very large library to learn. There are books about it alone. For leaner requirements I use psycopg2, simply because I use postgresql as my data store and it's pretty much the pythyon/postgresql de-facto standard. Internally this is what SQLalchemy uses to access a postgresql database. If you're on MySQL or Oracle or whatever your low level package will be different. What you use depends on your preferred learning style: top-down or bottom-up. If you already know SQL the bottom-up approach of learning the low level lib will serve you well and you'll feel more immediately productive. Good luck! -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: My son wants me to teach him Python
>> *Everything* these days revolves around graphical interfaces. The console, >> which was once the dark and mystical battlefield where knighted geeks would >> slay the plagues of exception demons, has been reduced to a mere: "little black >> box of nostalgia". >> 1. Rock is dead... >> 2. The console is dead... I use a console every day and I'm 28 years old. I write code for everything from Autodesk Maya to web API's to database backends. (Yes, GUI code too.) The console is far, far from dead. It has a steeper learning curve than a GUI but even in 2013 it's still invaluable. To date I have not met a good programmer who doesn't use a console on a regular basis. It's not the only tool in the box but, properly configured, it's a heck of a good one. I don't see this changing anytime soon. Back on topic... If he wants to learn game programming, teach him game programming. Don't push a bunch of prerequisites on him that he has to learn first. You'll only kill the spirit. There's plenty of time to learn the other stuff as needed. You might look at the Unity game engine. There's a lot of UI to start with for tweaking assets and a *lots* of programming. There's a free version and tons of documentation. You might consider signing up for www.digitaltutors.com/ for additional sources of documentation on both Unity as well as digital content creation software you'll be using along the way. This will feed his desire to learn due to the instant gratification of making a 3D "game" in an hour. Unfortunately, with Unity you don't get to write code in Python, but there's Boo script which is Python inspired, as well as JavaScript if he's already comfortable with that. (Eww... but even it has good parts.) If you decide to get seriously invested in digital content creation software (i.e. Maya, etc) most of those are scripted in Python. Maya used to be all MEL (and the MEL interpreter is still supported) but most new code for proprietary tools is done in Python. (MEL is kind of perverse in comparison.) Most important of all - keep it fun! -Modulok- On Wed, Jun 12, 2013 at 10:47 PM, Rick Johnson wrote: > On Wednesday, June 12, 2013 11:08:44 PM UTC-5, Chris Angelico wrote: > > > No. Definitely not. Programming does NOT begin with a GUI. It begins > > with something *simple*, so you're not stuck fiddling around with the > > unnecessary. On today's computers, that usually means console I/O > > (actually console output, with console input coming along much later). > > Chris, you're a dinosaur, only thing is, somebody forgot to tell you. > > *Everything* these days revolves around graphical interfaces. The console, > which was once the dark and mystical battlefield where knighted geeks would > slay the plagues of exception demons, has been reduced to a mere: "little > black box of nostalgia". > > 1. Rock is dead... > 2. The console is dead... > 3. Welcome to the 21st century Chris! > > PS: Although i'll bet you think the "rock is dead" mantra is relatively > recent, nope! Jim Morrison was singing about it waaay back in 1969! > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is the argparse module so inflexible?
Have you looked into docopt? -Modulok- On Fri, Jun 28, 2013 at 7:36 PM, Ethan Furman wrote: > On 06/27/2013 03:49 PM, Steven D'Aprano wrote: > >> >> [rant] >> I think it is lousy design for a framework like argparse to raise a >> custom ArgumentError in one part of the code, only to catch it elsewhere >> and call sys.exit. At the very least, that ought to be a config option, >> and off by default. >> >> Libraries should not call sys.exit, or raise SystemExit. Whether to quit >> or not is not the library's decision to make, that decision belongs to >> the application layer. Yes, the application could always catch >> SystemExit, but it shouldn't have to. >> > > So a library that is explicitly designed to make command-line scripts > easier and friendlier should quit with a traceback? > > Really? > > -- > ~Ethan~ > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- http://mail.python.org/mailman/listinfo/python-list
Re: password protect file
On Sat, 29 Jun 2013 10:28:47 -0700 (PDT), gmsid...@gmail.com wrote: > I was wondering if there was a couple of words or things i > could add to the top of my python script to password > protect it so that it asks user for the password and then > after three tries it locks them out or says "access > denied" and closes/ends the script but if they get it > wright it proceeds on to the next line of the script total > noob here any help appreciated How to correctly implement such features depends on what are you are protecting. Are you trying to protect another file on the same machine, the script itself? Is this a server-side script trying to authenticate a web client? Is this 'kid-sister' level protection or national security level of protection? We would need more details on what you're trying to accomplish. Also, good (i.e. real) security is notoriously difficult to get right. There are usually pre-built solutions you should make use of instead. >From your subject line it sounds like you're interested in access control. If this is on a controlled system you should instead make use of the pre-built operating systems access control features such as user accounts, file permission bits, group policies or Access Control Lists. If this is in an uncontrolled environment or you just want to protect a file on a USB stick from prying eyes you can encrypt the file with a strong symmetric cipher like AES. There are existing tools for doing this. Your Python script could be a wrapper around one of these. (There are certain security implications to be aware of when doing this.) There's also AES implementations available in various pure Python modules. (However these generally are not FIPS certified.) If you are a "total noob" attempting (real) security programming is a bad idea. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: Web Frameworks Excessive Complexity
> On Wed, Nov 21, 2012 at 10:43 PM, Steven D'Aprano > wrote: >> On Wed, 21 Nov 2012 22:21:23 +1100, Chris Angelico wrote: >> >>> Counting complexity by giving a score to every statement encourages code >>> like this: >>> >>> def bletch(x,y): >>> return x + {"foo":y*2,"bar":x*3+y,"quux":math.sin(y)}.get(mode,0) >>> >>> instead of: >>> >>> def bletch(x,y): >>> if mode=="foo": return x+y*2 >>> if mode=="bar": return x*4+y >>> if mode=="quux": return x+math.sin(y) return x >>> >>> Okay, this is a stupid contrived example, but tell me which of those >>> you'd rather work with >> >> > Oh, I'm *so* glad I work in a small company. Agreed. Do we rate a contractor's quality of workmanship and efficiency by the number of nails he drives? Of course not. That would be ridiculous. A better metric of code quality and complexity would be to borrow from science and mathematics. i.e. a peer review or audit by others working on the project or in the same field of study. Unfortunately this isn't cheap or easily computed and doesn't translate nicely to a bar graph. Such is reality. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: Secretly passing parameter to function
> Hi all ! > > I have a problem that is not easy to explained, so I have tried to > reduce it a lot. > > We are using a framework, that we can not modify. > > in framework.py: > def do(something): > ''' > Here we are in a framework that can not be modified ... > It does a lot of things > > and finally: > ''' > something() > > in test.py: > from framework import * > > def step1(): > print "Do step1" > > def step2(): > print "Do step2" > > > # We ask the framework to do some work. > do(step1) > do(step2) > do(step3) > > > We are writing step1, step2, ... and asking the framework to process them. > Everything is ok, until we want to add a parameter to some steps. > We want to be able to do that: > > in test.py: > from framework import * > > def step1(param): > print "Do step1 with param" > > def step2(): > print "Do step2" > > > # We ask the framework to do some work. > > do(step1, param = None) > do(step1, param = [0, 1, 5]) # again > do(step2) > > Of course it does not work ... > TypeError: do() takes exactly 1 argument (2 given) > > And we can not modify the framework (in which "do" is defined. > > One solution would be to use a global variable that can be set before > each step. But it is not very elegant ... > > One other approach would be to add dynamically an attribute the the > step1 function, and retrieve it inside the function, but it is perhaps > overkill. > > Do you have some ideas ? Olivier, I would create a partial object using the functools module, but I would also wrap it in a decorator so I could call my functions as usual. Here's an example: # File: framework.py: def do(something): print("Framework in action...") return something() # File: test.py: import functools import framework def pack(func): """Return a function object to be called later.""" def f(*args, **kwargs): """Call the framework passing a partial object to be called.""" print("Wrapper in action...") part = functools.partial(func, *args, **kwargs) return framework.do(part) #<-- Call the simplified function. return f#<-- Return the function object to-be-called. # Usage: Just wrap your defs with the decorator '@pack': @pack def step1(x, y): print(x, y) @pack def step2(a): return sum(a) @pack def step3(): print("Amazing!") # Call your functions as usual e.g: step1(3, 5)... In theory everything should just work. I tested the above example and it seemed to work just fine with my limited testing. Good luck! -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, do I need an IDE or is vim still good enough?
> 'Aloha! > > I'm new to python, got 10-20 years perl and C experience, all gained on unix > alike machines hacking happily in vi, and later on in vim. > > Now it's python, and currently mainly on my kubuntu desktop. > > Do I really need a real IDE, as the windows guys around me say I do, or will > vim, git, make and other standalone tools make it the next 20 years too for > me? > > Oh, by the way, after 7 days I'm completely in love with this python thing. > I should have made the switch much earlier! > > /mogul %-) No. If you want to test one out, great. If not, it's totally not required. I use jEdit (text editor) and a bunch of command line tools on FreeBSD. I've tried various IDEs and have yet to find one I totally agree with. Yet, I know guys who use them and wouldn't part with them 'til death. I always end up back in a customized text editor and a *nix command shell. I prefer it. There's a lot of *very* skilled programmers in both camps. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: Considering taking a hammer to the computer...
> I'm trying to help my son with an assignment and spending hours making an > inch of progress. I know nothing about programming and I'm trying to learn, > on my own, at a rate faster than possible. I would love a little help! > > My son is taking an introductory course and his assignment is to use the > loops for and while to create a program which calculates a hotel's occupancy > rate. He has managed all of the "inputs" but needs help with the following: > > 1) The first question asked is how many floors are in the hotel - and then > the questions are asked floor by floor. We can't figure out how to get the > program to stop questioning when the number of floors is reached. > > 2) He has programmed specific calculations for each floor, and now needs to > have calculations for the entire hotel based on the input about each > floor. > > Here is what he has done so far: > > > #This program will calculate the occupancy rate of a hotel > floor_number = 0 > > > number_of_floors = int(input("How many floors are in the hotel?: ")) > while number_of_floors < 1: > print ("Invalid input!") > number_of_floors = input("Enter the number of floors in the hotel: ") > while number_of_floors > 1: > floor_number = floor_number + 1 > print() > print ("For floor #",floor_number) > rooms_on_floor = int(input("How many rooms are on the floor ?: " )) > while rooms_on_floor < 10: > print ("Invalid input!") > rooms_on_floor = int(input("Enter the number of rooms on floor: ")) > > occupied_rooms = int(input("How many rooms on the floor are occupied?: > ")) > > #CALCULATE OCCUPANCY RATE FOR FLOOR > occupancy_rate = occupied_rooms / rooms_on_floor > print ("The occupancy rate for this floor is ",occupancy_rate) > > > > The following is what we believe needs to go in the program at the end > except we can't figure out how to calculate it and make it all work :/ (alot > of the terms have nothing at all to identify them yet...) > > hotel_occupancy = total_occupied / total_rooms > print ("The occupancy rate for this hotel is ",hotel_occupancy) > print ("The total number of rooms at this hotel is ",total_rooms) > print ("The number of occupied rooms at this hotel is ",total_occupied) > vacant_rooms = total_rooms - total_occupied > print ("The number of vacant rooms at this hotel is ",vacant_rooms) > > We've searched and read and we found things about the "break" and "pass" > commands but his teacher will not allow them because they haven't been > taught yet. > > If you have any ideas and can take a minute to help, that would be great :) > > Thank you! Here's your program with some extra comments to get you started: #This program will calculate the occupancy rate of a hotel floor_number = 0 number_of_floors = int(input("How many floors are in the hotel?: ")) while number_of_floors < 1: print ("Invalid input!") number_of_floors = input("Enter the number of floors in the hotel: ") # Remember you need to make sure this is an int, just like before. # number_of_floors = int(input("Enter the number of floors in the hotel: ")) Right now it's a string. while number_of_floors > 1: # This loop runs forever, as number_of_floors never changes. You need # to do something to `number_of_floors` such as de-increment it e.g: # `number_of_floors -= 1`, that way we will *eventually* have # number_of_floors less than 1, thus stopping the loop. A better # idea would be to use a `for` loop instead of the above `while` # loop. For example:: # # for i in range(number_of_floors): # # blah... do something for each floor. This loop auto-terminates. # floor_number = floor_number + 1 print() print ("For floor #",floor_number) rooms_on_floor = int(input("How many rooms are on the floor ?: " )) while rooms_on_floor < 10: print ("Invalid input!") # You might consider telling your user why their input is # invalid. e.g: "rooms on floor must be greater than 10". rooms_on_floor = int(input("Enter the number of rooms on floor: ")) occupied_rooms = int(input("How many rooms on the floor are occupied?: ")) #CALCULATE OCCUPANCY RATE FOR FLOOR occupancy_rate = occupied_rooms / rooms_on_floor print ("The occupancy rate for this floor is ",occupancy_rate) -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGreSQL 4.1 released
> --- > Release of PyGreSQL version 4.1 > --- > > It has been a long time coming but PyGreSQL v4.1 has been released. > > It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. > > If you are running NetBSD, look in the packages directory under > databases. There is also a package in the FreeBSD ports collection > which will probably be updated shortly. > > Please refer to `changelog.txt `_ > for things that have changed in this version. > > Please refer to `readme.txt `_ > for general information. > > This version has been built and unit tested on: > - NetBSD > - FreeBSD > - openSUSE 12.2 > - Windows 7 with both MinGW and Visual Studio > - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit > - Python 2.5, 2.6 and 2.7 32 and 64bit This is good news. The PyGreSQL team is doing a great job! Pass on my congrats :D -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: semicolon at end of python's statements
> So? Indeed there are too many people looking at these things as fighting > for the one true way. That is IMO part a big part of the problem. I have > no problem if someone else uses a different style than I do. Python as > a language tries too hard to enforce a one true way. > > Try maintaining a non-trivial body of JavaScript, or Perl (that you didn't write) for a while. You'll soon appreciate the One True Way of thinking lol. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: semicolon at end of python's statements
> But, more than that, it saves the zillions of hours of > time wasted arguing about which way is better. > XD Nice. That's about the best supporting argument I've heard. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: building an online judge to evaluate Python programs
On Fri, Sep 20, 2013 at 11:28 AM, Jabba Laci wrote: > Hi, > > In our school I have an introductory Python course. I have collected a > large list of exercises for the students and I would like them to be > able to test their solutions with an online judge ( > http://en.wikipedia.org/wiki/Online_judge ). At the moment I have a > very simple web application that is similar to Project Euler: you > provide the ID of the exercise and the output of the program, and it > tells you if it's correct or not. However, it can only be used with > programs that produce an output (usually a short string or a number). > > In the next step I would like to do the following. The user can upload > his/her script, and the system tests it with various inputs and tells > you if it's OK or not (like checkio.org for instance). How to get > started with this? > > There are several questions: > * What is someone sends an infinite loop? There should be a time limit. > * What is someone sends a malicious code? The script should be run in a > sandbox. > > All tips are appreciated. > > Thanks, > > Laszlo > -- > https://mail.python.org/mailman/listinfo/python-list How much time is it worth? Here's some ideas: Build a server just for grading student work that contains no valuable data, probably a virtual server on another machine. Something like virtualBox, etc. The code they submit is executed as a less privileged operating system user. For added security, you could look into using something like FreeBSD process jails but there's a learning curve there. I would not be overly concerned with security - put out a bounty as extra credit: He who hacks the server through the judge program, and provides details on how they did it, wins something great, even if it's just class notoriety. What is someone sends an infinite loop? There should be a time limit: Run their code as a separate process. If the process or its children run too long, kill them. On similar grounds you can use operating system features to define limits on maximum memory, disk usage, maximum number of processes, etc. On FreeBSD this can done via the `limits` command, other operating systems have their own versions of the same thing. Limits are useful, they prevent things like exhausting physical memory. What is someone sends a malicious code? If the server contains no valuable data, there's not much damage they can do other than using it for email spam or perhaps shutting it down. You could prevent email spam by a few firewall rules. To protect the judge program itself from being hacked set its permission bits to read only. It is *extremely* difficult to create a sandbox without using operating system (kernel enforced) features and access controls i.e. permission bits, process jails, kernel enforced hardware resource limits, etc. Don't be tempted to try it without these or you will likely fail. So long as the student program is run in a process owned by another, less privileged system user account, it shouldn't be able to modify the judge process which started it. For extra security you could even put the judge program on its own file system mounted as read-only. The resulting grades themselves would have to be stored elsewhere obviously, perhaps another server that has strict check constraints on what constitutes valid input no different than any web service. You can have yet-another process or even a process on another server watchdog your judge system. Send it a few test programs every x minutes. If it fails to respond with the expected results in the expected time frame - kill it and restart it. Test again. If it still fails consider it hacked (or broken). Do any graduate students or teacher's assistants owe you favors? -Modulok- -- https://mail.python.org/mailman/listinfo/python-list
Re: building an online judge to evaluate Python programs
> > > If you want to run untrusted Python code and prevent malice (or stupidity) > from harming you, you need OS-level protection. > > Agreed. Just for fun here's a simple example of what could be an honest mistake that consumes all physical memory and swap. A well behaved kernel will kill the process eventually when it can no longer allocate memory, but not before bringing the machine to its knees: class Foo(object): def __init__(self): self.x = 1 def __iter__(self): return self def next(self): self.x += 1 # Oops. In a well behaved iterator this should eventually # raise 'StopIteration'. I knew I forgot something. a = Foo() b = list(a) -Modulok- -- https://mail.python.org/mailman/listinfo/python-list
Re: Sexism in the Ruby community: how does the Python community manage it?
;t included enough? Are we to form a committee of name approvers? Do we delete or change potentially offensive names? What if that means we break other code that depended upon those names? Who decides what is offensive? In what culture? In what language? In what era? In what context? Do we extend this idea to the names of other identifiers like variables and functions? foo.fuck_off() Does that get excluded as well? How about the documentation? A very slippery slope. Perhaps we could enforce a naming convention that takes into account a balance of module names, some which appeal to female, some to male, some to black, to white, yellow, brown, - Darwin's grab bag. Of course, who decides the ratios that these names will appear in the module index? Do we mimic the human population, the community population or is it more about equal slices all around? We could pick random words from the dictionary - My mistake. I just found 'fuck', 'bitch', 'sex', 'retard', 'shag', 'ass', 'womanizer' and 'hoe' listed there too. There are others as well! Maybe we can start a sister project to manage offensive words found in the dictionary! Or should that be a 'brother' project? A sibling project, perhaps? Hmm. ~~~ If I want to name a module `fuck_off_and_die`, I should be perfectly allowed to do so. It's my module, my code, my project - my choice. Does it make me an insensitive prick? Maybe, but I'd be very hesitant to judge someone's personal character based solely on the name of a python module. To do otherwise would render the one passing judgment a pretentious prick - really no better. Does it lack professionalism? Perhaps. Is the module itself useful? Now that's a far more important question. The day we come up with a blacklist of forbidden names and start excluding what could otherwise have been useful bits of publicly available code - a charitable work of skilled labor - I think we will have lost something far more valuable than having a G-rated module index. That said, I appreciate and try to express professionalism in all that I do and encourage others to do the same but I also embrace the freedom of myself and others to choose - even if I think that choice is sexist and distasteful. I would rather experience the freedom of having the full latitude of life, decision and emotion, than to cower in fear of being offended by the world at large. To think that I would be capable of being offended by the arrangement of a glyph in a programming package index, is a ridiculous thought indeed. Yup. -Modulok- -- https://mail.python.org/mailman/listinfo/python-list
Re: Algorithm that makes maximum compression of completly diffused data.
On Wed, Oct 30, 2013 at 12:21 PM, wrote: > I am searching for the program or algorithm that makes the best possible > of completly (diffused data/random noise) and wonder what the state of art > compression is. > > I understand this is not the correct forum but since i think i have an > algorithm that can do this very good, and do not know where to turn for > such question i was thinking to start here. > > It is of course lossless compression i am speaking of. > -- > https://mail.python.org/mailman/listinfo/python-list >> I am searching for the program or algorithm that makes the best possible of >> completly (diffused data/random noise) and wonder what the state of art >> compression is. None. If the data to be compressed is truly homogeneous, random noise as you describe (for example a 100mb file read from cryptographically secure random bit generator such as /dev/random on *nix systems), the state-of-the-art lossless compression is zero and will remain that way for the foreseeable future. There is no lossless algorithm that will reduce truly random (high entropy) data by any significant margin. In classical information theory, such an algorithm can never be invented. See: Kolmogorov complexity Real world data is rarely completely random. You would have to test various algorithms on the data set in question. Small things such as non-obvious statistical clumping can make a big difference in the compression ratio from one algorithm to another. Data that might look "random", might not actually be random in the entropy sense of the word. >> I understand this is not the correct forum but since i think i have an >> algorithm that can do this very good, and do not know where to turn for such >> question i was thinking to start here. Not to sound like a downer, but I would wager that the data you're testing your algorithm on is not as truly random as you imply or is not a large enough body of test data to draw such conclusions from. It's akin to inventing a perpetual motion machine or an inertial propulsion engine or any other classically impossible solutions. (This only applies to truly random data.) -Modulok- -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating a reliable sandboxed Python environment
While this thread is indeed a theoretical discussion of the interpreter, for a practical solution where you control the host environment, one might look into OS level sandboxing like FreeBSD's Jails (not to be confused with a simple chroot environment) along with various resource limiting parameters. You can lock down a 'sandboxed' i.e. jailed environment for arbitrary data and processes, including python, pretty tightly. -Kurt- On Sat, May 30, 2015 at 5:52 PM, Steven D'Aprano wrote: > On Sat, 30 May 2015 09:24 pm, Laura Creighton wrote: > > > In a message of Sat, 30 May 2015 19:00:14 +1000, "Steven D'Aprano" > writes: > >>I wouldn't have imagined that the claim "it's easier to secure a small > >>language with a few features than a big language with lots of features" > >>would have been so controversial. I wonder if this claim will be equally > >>as controversial? > >> > >>There is a rough correlation between the number of lines of code in a > code > >>base, and the number of potential security holes that need to be guarded > >>against. > > > > Maybe these aren't controversial if you are doing langauge level > > sandboxing, but you don't have to sandbox like that. Consider, for a > > moment, the sandboxing technique used by PyPy > > discussed at > > > > http://pypy.readthedocs.org/en/latest/sandbox.html > > > > You think it is way cool, but, alas, you want to sandbox some other > > language than Python. > > How many PyPy sandboxes are being used with hostile users motivated to > break > out of the sandbox? > > "I wrote a sandbox which I can't break out of" is different from "I wrote a > sandbox which nobody can break out of". Javascript is sandboxed, but due to > bugs in implementations, Javascript-based exploits are now heavily used by > malware. There are possibly even more Javascript-based exploits than buffer > overflow based exploits these days, as C programmers get better at using > automated tools that check for buffer overflows. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
OT - information theory thing...
I'm trying to remember something I read one night to do with information theory to vague for Google to help much. If anyone could help me remember that would be wonderful! It had something to do with the fact that, given a transmission medium, you can control whether information flows or not, but it is impossible to control *what* information flows. (Due to the possibility of nested encoding, stenography, etc.) Was this a Claude Shannon thing or Alan Turing or... I really don't recall. Thoughts? Cheers! -Modulok- -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?
> I'm using Python for a while now and I love it. There is just one thing I > cannot understand. There are compilers for languages like C and C++. why is > it impossible to create a compiler that can compile Python code to > machinecode? Not exactly what you describe, but have you checked out PyPy? http://pypy.org/ -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: Store a variable permanently
>> Installing and running a database for a single integer is like using a >> using a bulldozer for moving your keyboard half an inch to the left. I'd like to see that sometime XD -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: The usage of -m option of python
>> Hi, >> >> I don't quite understand how -m option is used. And it is difficult to >> search for -m in google. Could anybody provide me with an example on >> how to use this option? Thanks! >> >>-m module-name >> Searches sys.path for the named module and runs the >> corresponding .py file as a script. > I don't quite understand how -m option is used. And it is difficult to > search for -m in google. Could anybody provide me with an example on > how to use this option? Thanks! Forgive me if I'm too verbose: When this module is imported via a regular python import statement, the module's special property ``__name__`` is automatically set to the name of the module, as a string. For example:: >>> import random >>> random.__name__ >>> 'random' If a file is executed as a script from the operating system's command line, the value of the ``__main__`` property is instead automatically set to the string "__main__". This is useful because many python modules have a line such as:: if __name__ == "__main__": # Do something different... # Maybe run some unit tests or something. # Or perhaps parse some command line arguments... This means you can cd into the python modules directory on your system and execute one of the built-in modules directly:: cd /usr/local/lib/python3.3 python3.3 random.py # Tests the random number functions and spits out the result to the # console. We have one file with two behaviors, depending on how it gets executed. You can use the same concept in your own scripts to have both a command line script that does something useful, as well as an importable python module to use in other scripts. Remember, if ``__name__ == "__main__"`` the file is being run as a script. Otherwise it's being imported as a module. So what about that ``-m`` option? Having to cd into the python module directory every time you need to execute a module as a script is cumbersome. The ``-m`` flag is basically a shortcut. These are basically the same:: cd /usr/local/lib/python3.3 python3.3 random.py Same as:: python3.3 -m random #<-- I can do this from any directory. The modules in the standard library have no obligation to do anything useful, or even anything at all, if execute directly but you can use the same idea to execute modules as scripts from packages you create. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: django vs zope vs web2py
> Hi everyone, > few months back I decided to adopt python for my all sort of work including > web programming... > -- > http://mail.python.org/mailman/listinfo/python-list > Pick Django or web2py. You'll be happy with either. (I have no experience with zope.) They're both full featured do-everything-you-ever-wanted frameworks with great communities and lots of documentation. You can buy books on either. I'd say web2py is a little more elegant and easier to get started with. (An admittedly subjective claim.) Django has a little larger community and has more third party stuff. If you just need to "get it done" and don't care about how it happens, they're both excellent. You'll meet deadlines with either of them. The communities are smart the docs are great. You can't really go wrong any way you slice it. There's more third party documentation and books for Django right now but that's just because Django came out first. Give it another couple years and there won't be much difference. Basically, flip a coin and just go with it. And now for the gritty details approach... The problem with web frameworks is they are "magic", i.e. things just happen. It's the price we pay for using a high level abstraction. The higher the abstraction the more magic there is. Often times magic is good. It saves us time and money. However depending on your needs, other options are worth considering. If you are willing to invest a lot of time not being initially productive but learn a *ton* in exchange, you can use something like cherrypy. (Don't get me wrong, I love and often use cherrypy.) It's dirt simple and works. However, because it's so simple it doesn't do half of what you need for a non-trivial production site. Result? You'll have to fill in the tool chain gaps with other modules. This is what web frameworks do for you. If you go the cherrypy route you'll need to learn other things like like markup languages and some kind of way to talk to a database. Security is also entirely in your hands. You'll learn a ton about HTTP, SQL, markup languages, web security, encryption, etc. You'll be basically re-creating a web framework of your own brand. Again it's a time spent vs. knowledge gained trade off. For a template language I really liked wheezy.template but it's a little too new for me to feel comfortable using it on any big project. It has a very simple inheritance model, which is refreshing. I hope to use it more in the future. I usually use Mako for my templates. By 'template' I mean any template, not just HTML. I use mako for HTML, documentation, I even use mako to write SQL templates. The inheritance model of Mako takes a little more mental gymnastics to wrap your head around than the simpler (read nicer) wheezy.template model, but it's a more mature code base. (Not as mature as cheetah.) I had only minor experience with cheetah but found I preferred Mako. It was a matter of taste. There's nothing wrong with cheetah. As for database access: sqlalchemy is truly excellent and very flexible. For most things sqlalchemy is great. However for some projects it may contain too much magic. (Again we're going deeper.) Sometimes a backend-specific module is called for, in which case psycopg2 on postgresql is nice. The ability to use python context managers as transaction blocks is very clean. In short, how much do you want to learn? Do you prefer a top-down or bottom-up approach? Gritty details or elegant abstractions? -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to count sequences
On 4/25/13, Denis McMahon wrote: > On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote: > >> I have to count the number of various two-digit sequences in a list such >> as this: >> >> mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence >> appears 2 times.) >> >> and tally up the results, assigning each to a variable. ... Consider using the ``collections`` module:: from collections import Counter mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] count = Counter() for k in mylist: count[k] += 1 print(count) # Output looks like this: # Counter({(2, 4): 2, (4, 5): 1, (3, 4): 1, (2, 1): 1}) You then have access to methods to return the most common items, etc. See more examples here: http://docs.python.org/3.3/library/collections.html#collections.Counter Good luck! -Modulok- -- http://mail.python.org/mailman/listinfo/python-list