Code Monkey home page Code Monkey logo

pp's Introduction

Python Playground

Code for all the projects in the book Python Playground published by No Starch Press, USA.

You can find more information about the book here.

The source code is published here as per the MIT License below:

The MIT License (MIT)

Copyright (c) 2016 Mahesh Venkitachalam

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pp's People

Contributors

bryant1410 avatar mkvenkit avatar mortalcatalyst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pp's Issues

reading files

i am new to programming and dont understand calling the final code playlist.py to read specified files. how do i run the programme?

Will not save .png form of file

EDIT: After the installation of Ghostscript 9.50, which I obtained from
https://pages.uoregon.edu/koch/Ghostscript-9.50-Full.pkg,
the program writes the png file as expected on key "s" -- PIL requires the presences of Ghostscript, which is not provided with the purchase of a Mac.

Using python 3.8.1 and the current version of PIL:
on keys "t" or " ", the program toggles or restarts as expected.
on key "s", the program writes the .eps file, but it does not write the .png file. The program continues to run and produces the following error message when it fails to write the png file.

generating spirograph... saving drawing to spiro-09Jan2020-114601.eps/png Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__ return self.func(*args) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/turtle.py", line 686, in eventfun fun() File "/Users/richardkopcke/PycharmProjects/Python_Playground/ch2_spirograph/original.py", line 191, in saveDrawing img.save(fileName + '.png', 'png') File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/Image.py", line 2068, in save self._ensure_mutable() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/Image.py", line 589, in _ensure_mutable self._copy() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/Image.py", line 582, in _copy self.load() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/EpsImagePlugin.py", line 330, in load self.im = Ghostscript(self.tile, self.size, self.fp, scale) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/EpsImagePlugin.py", line 143, in Ghostscript subprocess.check_call(command, startupinfo=startupinfo) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 359, in check_call retcode = call(*popenargs, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 340, in call with Popen(*popenargs, **kwargs) as p: File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'gs'

No module named glutils

Ref to code in folder volrender

The files raycast.py, raycube.py, slicerender.py import another module called glutils but the module is no where found in the code.

Thanks the book has been an engrossing read so far !

b'invalid operation' in volrender.py

I'm attempting to work through the Volume Rendering chapter. Love the book! This may be a driver or system error but any tips for teasing out this error would be greatly appreciated!

  1. I'm using windows7 64 bit and python 3.4 64bit (I made sure with platform.architecture())
  2. I downloaded the 64bit glfw binaries from http://www.glfw.org/download.html
  3. I copied glfw3.dll from the libvc-2012 folder into volrender.py and hardcoded the path to the dll in volrender.py. That seems to be working because glfw.glfwInit() returns 1
  4. I get "invalid operation' error when it get to the glViewport() call.

image

DeprecationWarning: The readPlist function is deprecated

The code presents the following error:

anatomyPlaylist.py:16: DeprecationWarning: The readPlist function is deprecated, use load() instead
plist = plistlib.readPlist(fileName)
Traceback (most recent call last):
File "anatomyPlaylist.py", line 162, in
main()
File "anatomyPlaylist.py", line 149, in main
findCommonTracks(args.plFiles)
File "anatomyPlaylist.py", line 16, in findCommonTracks
plist = plistlib.readPlist(fileName)
File "C:\Users\ext.renatoss1\AppData\Local\Programs\Python\Python37-32\lib\plistlib.py", line 100, in readPlist
return load(fp, fmt=None, use_builtin_types=False)
File "C:\Users\ext.renatoss1\AppData\Local\Programs\Python\Python37-32\lib\plistlib.py", line 944, in load
raise InvalidFileException()
plistlib.InvalidFileException: Invalid file

I've changed the line:

plist = plistlib.readPlist(fileName)

to

plist = np.load(fileName)

but, the error changed to:

Traceback (most recent call last):
File "C:\Users\ext.renatoss1\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\lib\npyio.py", line 440, in load
return pickle.load(fid, **pickle_kwargs)_pickle.UnpicklingError: invalid load key, '\x0a'.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "anatomyPlaylist.py", line 162, in
main()
File "anatomyPlaylist.py", line 149, in main
findCommonTracks(args.plFiles)
File "anatomyPlaylist.py", line 16, in findCommonTracks
plist = np.load(fileName)
File "C:\Users\ext.renatoss1\AppData\Local\Programs\Python\Python37-32\lib\sit
e-packages\numpy\lib\npyio.py", line 443, in load
"Failed to interpret file %s as a pickle" % repr(file))
OSError: Failed to interpret file 'maya.xml' as a pickle

Of course there is some other modification to make, but I can't figure it out yet.

Advices?

Thanks and sorry for my poor english.

Difficulty with volrender.py

I am using Spyder (Python 2.7) with Anaconda and trying to get volrender.py to work. I had to make one change. Anaconda likes pyglfw so i loaded this and changed 'import glfw' to 'import pyglfw as glfw'. This works.

Now when i try to compile and run, i get the following error:
Reloaded modules: raycube, volreader, glutils, slicerender, raycast
starting volrender...
usage: volrender.py [-h] --dir IMAGEDIR
volrender.py: error: argument --dir is required
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
entering %tb i get:
%tb
Traceback (most recent call last):
File "/Users/jamesbranch/anacondaPython2.7/anaconda/lib/python2.7/site-packages/spyder/utils/ipython/start_kernel.py", line 198, in main
locals().pop('file')
KeyError: 'file'

I would be most appreciative if i could get some advice on how to fix this.

simpleglfw not using core profile 3.2 as claimed in comment

OpenGL Version 	GLSL Version
2.0 	1.10
2.1 	1.20
3.0 	1.30
3.1 	1.40
3.2 	1.50
3.3+	3.30

The shader only actually needs very minor changes to work as a core profile 3.2 shader (1.50) and therefore work when opening a 3.2 context instead of 3.3

[Chapter 1 Resource] Here's the XML structure of the iTunes playlist - Hope this helps

<dict>
<key>Track ID</key><integer>35</integer>
<key>Name</key><string>Landslide</string>
<key>Artist</key><string>Fleetwood Mac</string>
<key>Album</key><string>The Dance</string>
<key>Genre</key><string>Rock</string>
<key>Kind</key><string>Protected AAC audio file</string>
<key>Size</key><integer>4285488</integer>
<key>Total Time</key><integer>268283</integer>
<key>Disc Number</key><integer>1</integer>
<key>Disc Count</key><integer>1</integer>
<key>Track Number</key><integer>9</integer>
<key>Track Count</key><integer>17</integer>
<key>Year</key><integer>1997</integer>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
</dict>

javascript files doesn't loads up while server is running on localhost

keep getting error:
pi@raspberrypi:~/myProjectDir $ sudo python piweather.py --ip localhost --port 8080 starting piweather...
piweather.py:208: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(18, GPIO.OUT)
Bottle v0.12.17 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.

127.0.0.1 - - [31/Oct/2019 16:34:31] "GET /plot HTTP/1.1" 200 3396
127.0.0.1 - - [31/Oct/2019 16:34:38] "GET /jquery.js HTTP/1.1" 404 725
127.0.0.1 - - [31/Oct/2019 16:34:39] "GET /jquery.flot.js HTTP/1.1" 404 730
127.0.0.1 - - [31/Oct/2019 16:34:39] "GET /jquery.flot.time.js HTTP/1.1" 404 735

no flot/ directory is found in OS.

the code i used is same and code file are placed in /myProjectDir/ where all the jquery files are placed which are not loading.
https://raw.githubusercontent.com/electronut/pp/master/piweather/piweather.py

plz tell where to place the piweather.py file so that the server loads the jquery file and where to change the file.

i had created the issue :
bottlepy/bottle#1176
Issue is still not fixed.

IOError: [Errno 32] Broken pipe

When I press "s", the console shows:

saving drawing to spiro-08Oct2018-133122.eps/png
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1541, in call
return self.func(*args)
File "C:\Python27\lib\lib-tk\turtle.py", line 710, in eventfun
fun()
File "C:/pythonlearning/PythonPlayground/eg_2 kleidoscope/spiro_original.py", line 192, in saveDrawing
img.save(fileName + '.png', 'png')
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1406, in save
self.load()
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 283, in load
self.im = Ghostscript(self.tile, self.size, self.fp)
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 72, in Ghostscript
gs.write(s)

I opened the folder, finding the picture was not be saved as png.

Not finding duplicates...

Even with a simple playlist I made specifically for testing that only contains the same song 3 times, the code is not finding duplicates. Tried with the 'test files' too - same result. Issue appears to be that the xml file only lists the tracks once, and then refers to them as many times as required further down in the Playlist Items dictionary. The code looks for duplicates in the Tracks dictionary - but the xml file doesn't repeat duplicates there, so the code always returns no duplicates.

Has the plist format changed since this code was written, or am I missing something else?

Is there a license for the codes in this book?

I purchased a Kindle version of this book and it's a really useful book.
I'd like to use some of the project code to practice with OOP design and refactor (just for fun maybe). And I want to post them on my own repo in order to review my track better. I want to know is there any license for those projects. I can't find one in the repo.

code error

In project photomosaic.py, in line 180:

if not reuse_images: 
    input_images.remove(match)

I wonder variable ‘match' is miswritten. it is never defined in codes. But I don't know what it should be replaced?

small error in laser.py

hi sir,i executed laser.py in windows in a cmd but when i given --port COM3 executed.
but ,small error saying
AttributeError:'module' object as no attrubute 'Serial'

where is test1 function in ch5?

test1 is presumbly the python way to apply the rules, where test2 is numpy way. Would be helpeful to see both versions and compare.

Karplus-Strong Algorithm

When I execute the ks.py file downloaded from here using --display --play, the random tones play as expected, however, when I use only the --play parameter, it creates/skips files but no random tones are played. Also, when using --display, the plot appears, but remains blank, unless I run it in a debugger. I'm using Python 2.7.12, and there are no exceptions or errors appearing in the console. Is this a python 2.7 vs 3 issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.