Any tips on creating a Pygame Developer Console? - python-3.x

I've been getting my feet wet with Python and Pygame, and after a few bugs in a very basic game that I have been making, I've thought to myself that having some sort of console that can deal with string input (from a developer) would be very handy.
Here's an example:
I notice the player disappears after double jumping. So, in the console that I will hopefully create, I would type in:
>> report_bug("Player disappears after double jumping")
Where report_bug(string) is a user-defined function that will do the following things:
report_bug(string):
# Check if debug file already exists; create new file if none exists
# Append string to file, along with other extra info
Could someone point me in the right direction? Will I have to create something from scratch, and if so, how would I go about doing that? I've attempted to modify the source code from: http://www.pygame.org/project-pygame-console-287-.html, however it is 9 years-old and made for Python 2.x, when I'm using Python 3.4. Any help would be greatly appreciated.

I've managed to get the 2.X PygameConsole version 0.7 working, so I will stick with that!
Edit: I will attempt to port PyConsole to Python 3.X and hopefully add some more features so newcomers can easily understand what is going on.

Related

PyDTMC output graph overlaps on code in a notebook

I just installed PyDTMC and use it in a Jupyter notebook.
Following the examples on this page https://pypi.org/project/PyDTMC/ leads to a surprising result: plot_graph() overlaps on code above.
How could I fix that?
(m.plot_graph(mc, dpi=200) shows the full graph, but I don't like this workaround)
Note: jupyter-notebook 6.3.0, Python 3.8.5, PyDTMC 4.9.0 (on Archlinux)
The problem was mentioned here https://github.com/TommasoBelluzzo/PyDTMC/issues/6 with a fixing suggestion. Fix applied in this fork https://github.com/yagu0/PyDTMC.
It's still unclear why the figure size needs to be augmented (setting a higher dpi also works, but doesn't look like a clean solution). So I let this post open, in case of someone could explain :-)

ENSDFSTATE.dat file not found error while running exampleB1.exe using Geant4

I am new in Geant4. i installed and build GEANT4 using cmake and visual stdio 17 on windlows 10 and now i am trying to practice its given basic exapmles, So, I build first example using cmake by following the toturial given here. The example build successfully and created the exampleB1.exe file. I have set up all environment variables to data installed as given in screen shot
but facing the problem of still relating to environment vairiable is the screenshots of error
I looked this ENSDFSTATE.dat file but could not be able to solve the problem. Any suggestions/ support is highly appreciated.
It looks like your "G4ENSDFSTATEDATA" environmental variable is pointing to the wrong data set. Edit this variable to point to G4ENSDFSTATE2.2 location (i.e. D:\GEANT4\share\Geant4-10.5.1\data\G4ENSDFSTATE2.2 instead of D:\GEANT4\share\Geant4-10.5.1\data\G4PARTICLEXS1.1) and should work fine for that one. Double check your other environmental variables are correct also. Looks like G4ABLADATA should be G4ABLA3.1 for example.
Here is the list of all variables from the getting started manual (http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/postinstall.html):
Good luck!

How can i preserve the source raster projection when using gdal_translate?

I'm currently working on a small raster refining tool. The goal is, to have a simple CLI tool, to compute tiles from a georeferenced source raster and create a corresponding index.shp. For this I'm using python 3.7 and gdal. The tool runs smoothly and generates the expected tiles and shapefile, but it gets rid of the projection, which is stored in the source raster. Qgis defaults the newly computed tiles to EPSG 4326 while informing me about an unknown projection. The original raster is in EPSG 25832.
My Setup:
Windows 10 64 bit
Python 3.7.2
Gdal I cannot access the specific version, since gdal-config is not installed and I cannot make it work, but it is 64-bit and I installed it through the binaries provided on gisinternals.com. Windows software list says GDAL 204 MSVC 2017.
While running the script, I get error messages telling me about missing files, e.g. pcs.csv, datum.csv ellipsoid.csv and so on. This indicates that having those files, would fix my problem.
But oddly enough, I have used Osgeo4W to install, python 2.7 with gdal and it works like a charm, of course having adjusted the python parts. Tiles get calculated and stay in the projection of the source. Without any external files which specify a projection, in fact using the exact same data which is really confusing to me.
To my understanding, there is no flag or option which forces gdal to keep the projection. If have overlooked or missunderstood the docs im glad for advice.
Before anyone asks, i know that using the osgeo4w installer is obviously the easy and working solution here. But keeping in mind that python 2.7 will soon be discontinued and also using this as a chance to learn new things i wanted to build a 3.7 based tool with gdal installed on my machine
The corresponding code looks like this and does the following :
1.) Command string is build
2.) string is handed to os.system, which in turn executes accordingly
for i in range(0, width, tilelenght):
y = 0
for j in range(0, height, tilelenght):
gdaltranString = f'gdal_translate -of GTIFF -srcwin {i}, {j}, {tilelenght}, {tilelenght} {input_filepath} {output_filepath}{x}_{y}.tif'
subprocess.run(gdaltranString)
y = y+1
x = x+1
The expected result, would be a collection of functional .tif files which have the EPSG code of the source file, in this case 25832.
But as already mentioned, the projection gets lost somewhere in the process.
So,i have found the solution to my problem, without really understanding how it became an issue to begin with.
The solution was to create an user variable GDAL_DATA with the path to the projection definition files.
The weird thing is, i now have GDAL_DATA, as system variable and user variable, both pointing to the same directory.
If someone knows more about the mysterious ways of windows system variables, please share your wisdom, or the source of said wisdom.

python 3.x readlines()

After a pause I've currently started to work with python again but right at the start I encountered an annoying (and at least for me not solvable...) problem. I want to open a normal .txt file with tabular content so I can iterate over specific 'columns' to gather all the information I need. The problem is that I don't get each line of the document as a list but instead python creates strings of each line.I also tried .readlines() but thats doesn't work either.
I work on a Win7 PC and the code goes as followed:
with open('C:\\filepath...\\file.txt') as file:
for f in file:
print(f[0])
I also have to add that I also worked with python in the past and never encountered such problem so if anyone knows a solution I would really appreciate some help. Thank you in advance.
you just need to split:
TheList = []
with open('C:\\filepath...\\file.txt') as file:
for f in file:
TheList.append(f.split('\t'))

Output generated is different with output in NLTK tutorial

Today I start to learn Python because I need to use NLTK in my assignment. In order to learn it, I follow the tutorial in this site http://www.nltk.org/book/ch01.html. However, when I run the programme in Python interpreter, the output produced is not same with what has been shown in the website and I have no idea on what thing that this output wants to tell me.
(Below is the picture of the output:)
Input: >>> from nltk.book import *
Output (After I hit 'Enter'):
So now my questions are what is the error about and if there is a way to solve it, then what should I need to do?
Thanks for looking into my problem.
This appears to be a known bug with nltk and Python 3. It seems to have been fixed within the past two weeks, but I expect you'll have to wait until there's a release that contains the fix. You could try installing from source.

Resources