electronut / pp Goto Github PK
View Code? Open in Web Editor NEWCode for book Python Playground by Mahesh Venkitachalam (No Starch Press, USA)
Code for book Python Playground by Mahesh Venkitachalam (No Starch Press, USA)
My python: v3.6.1
python playlist.py --dup test-data/rating.xml
output:
...
TypeError: a bytes-like object is required, not 'str'
in findDuplicates()
, changing
f = open("dups.txt", 'wb')
to
f = open("dups.txt", 'w')
will fix it.
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?
<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>
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
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'
test1
is presumbly the python way to apply the rules, where test2
is numpy way. Would be helpeful to see both versions and compare.
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 !
i am new to programming and dont understand calling the final code playlist.py to read specified files. how do i run the programme?
I found glfw a python module on pypi. So we can use it, stead of implementing it again.
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.
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!
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?
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.
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.
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.
In the code listing, the shader code seems to be commented out??
GLFW library not found
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'
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.
EDIT: despite these error flags in PyCharm, the program does run.
at
https://github.com/electronut/pp/blob/master/spirograph/spiro.py
in lines 116, 117, and 127
the PyCharm (Python 3.8.1) flags the methods turtle.window_width(), turtle.window_height(), and turtle.ontimer(...) with an unresolved reference error.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.