Python - L error in declaration - python

I have tried to use this code: http://www.cgtk.co.uk/data/gemf/generate_efficient_map_file.py to create GEMF file from map tiles. Problem is, when I run this code with specific folder as a parameter, eg. "py generate_efficient_map_file.py Mapnik", I get error on line 6.
File "generate_efficient_map_file.py", line 6 file_size_limit = 2000000000L
And mistake is in word L. How to solve this, when there is a declaration error?
Thx

Try running it like this
python generate_efficient_map_file.py dirname
This works fine for me (no line 6 error - I don't have input data) on python 2.7.3. You can check your python version with
python -V

Related

About VSC, it doesn't work well(Python, windows)

When I run python code in the VSC, there's a problem.
When I initially run shift+enter to run each code in a particular line, it works well. However, after then that, when I try to run the overall code by using triangle button, there's a problem.
Same as the above, when I initially run the overall code by using triangle button, then I can't run each of code in one line with shift+enter
ex.1) When I use loop code like 'for i in range~..', the loop code works well. But when trying to do it by running the overall code, it doesn't work(specially, terminal shows that there's an indentation error.
2x.2) When I call some files on my C drive, I can call it by using shift+enter to run each code. And when I try to do it by using triangle code to make it, it doesn't work with error(invalid syntax).
(result with using shift+enter to call files)
import os
file_path = os.path.join('enron1/ham/0007.1999-12-14.farmer.ham.txt')
(result with running overall codes)
& C:/Users/gram/AppData/Local/Microsoft/WindowsApps/python3.10.exe c:/Users/gram/Desktop/강의/기계학습/Practice/test.py
File "<stdin>", line 1
& C:/Users/gram/AppData/Local/Microsoft/WindowsApps/python3.10.exe c:/Users/gram/Desktop/강의/기계학습/Practice/test.py
^
SyntaxError: invalid syntax
(reference)
I re-installed VSC and other python files(Anaconda3) to fix this problem, it was useless.
File "", line 1
first you need to get out from the this triangle line(>>>) by write >>>ctrl+z
then you can run your entire code .

Python Def Syntax Error with . in file name

In my Visual Code Studio running python3.6 - my code is saved as "Langemead12Test.py" w/ lines as:
!C:\Users\Bones\Anaconda3\python.exe
[1]def readFastq(SRR835775_1.first1000.fastq)
Red Error underline def [pylint] E0001:invalid syntax (, line 3).
In Anaconda command prompt running python3.6:
File "Langmead12Test.py", line 3
def readFastq(SRR835775_1.first1000.fastq)
^
SyntaxError: invalid syntax
Question(s): I'm a total newb here but I can't seem to understand why VCS throws an error under def and my anaconda command line prompt throws error at the . within the fastq filename. Are these independent errors or different representations of the same error? All thoughts and hints are welcome.
Background: I am attempting to execute exercise in ADS1: Practical: Working with sequencing reads. Ben Langmead's Youtube class on reading fastq files (filename = SRR835775_1.first1000.fastq).
You have 2 syntax error in one line:
1.Missing "" or this '' before and after your string
2.You forget to put ":" and the end of the line:
Correct syntax:
def readFastq(filename="SRR835775_1.first1000.fastq"):
Read this carefully please:
https://docs.python.org/3/tutorial/introduction.html#strings
https://docs.python.org/3/tutorial/controlflow.html#defining-functions
And after that read and learn everything from there:
https://docs.python.org/3/tutorial/index.html

Python won't create / write to a file

I am new at python and learning the language. The following code should create a file in the running program directory and write to it but it doesn't do this at all in a .py file. If I put the same code in the IDLE shell it returns 17. No errors just doesn't create the file. What am I doing wrong?
with open("st.txt", "w") as f:
f.write("Hi from Python!")
Thanks for the help
Mike
This code is flawless, no problem!
I guess that in your REPL shell, the $PWD environment variable is set for somewhere, so your destination file is in some corner.
No exception thrown indicates that no problem with access authority.
Maybe you can set some absolute path string, such as ~/st.txt
By the way, the successful invoke should return 15 instead of 17, totally count 15 chars.
your code works well, st.txt will be touched at executing path.
other ways, your system account can't write in your execute path.
try in your $HOME path to execute your code, I think, It will work well

Python 3 from CMD

I am attempting to run this .PY file from Command Prompt:
# Merge two .BSG files
# Starting block and world position are taken from the first file
# Example: "bsgmerge input.bsg output.bsg merged.bsg"
import io, sys
one = open(sys.argv[1]).readlines()
two = open(sys.argv[2]).readlines()
for n in [1,3,5,7,9,11,17,19,21,23]:
one[n] = one[n][:-1]+"|"+two[n].partition("|")[2]
open(sys.argv[3],"w").write("".join(one))
It is a program that takes a creation from the game Beseige and merges it with another saved creation so that opening the merged file results in both creations being present. If you want more details, you can read up on that here.
I am having trouble figuring out how to call this program from the command line. At first I thought the problem was me having Python 2 (it requires Python 3), so I uninstalled 2 and installed 3. This did not help.
What I am doing is entering the "python" command to pull up the Python environment within CMD, then entering the command to call the program based on the third comment in the file ("bsgmerge input.bsg output.bsg merged.bsg").
I tried using full file paths or simply changing to the correct directory before typing the "python" command and using only the file names, but so far I've had no luck.
When I am in the correct directory, then enter the Python environment, typing the command "bsgmerge 1.bsg 2.bsg M.bsg" (my existing files to be merged are 1.bsg and 2.bsg), this error occurs:
File "<stdin>", line 1
bsgmerge 1.bsg 2.bsg M.bsg
^
SyntaxError: invalid syntax
I took a Python course (which is why I used to have Python 2 on my machine) last fall, so I noticed that there is no "def" defining a function in the above code, which is something I've never encountered, so I'm thinking that is the root of my problems.
Thanks in advance for the help.
I was probably same problem with python launcher.
If you use Linux, first line shoud be:
#! /path/to/your/python/3
In Windows it some more complicated:
In registry by regedit change
HKEY_CLASSES_ROOT\Python.File\shell\open\command from "C:\Python27\python.exe" "%1" %* to "C:\Windows\py.exe" "%1" %*.
And first line of script shoud be:
#! python3
Now it shoud work properly.

Access Windows file from Python

I am new to Python, and despite my searching, am unable how to properly access a file from a Python Script on Windows with Python 3. I am trying to use Mongosm to import openstreetmap OSM data into mongodb, but get an error when trying to access the file. How can I fix this? Thank you. According to the github instructions, all I need to do is python insert_osm_data.py <OSM filename> (instructions found here)
The error says:
C:\Users\Jusitn>python C:\Users\Jusitn\Desktop\mongosm-master\insert_osm_data
G:\OSM\planet-140430.osm
File "C:\Users\Jusitn\Desktop\mongosm-master\insert_osm_data.py", line 160
print 'node not found: '+ str(node)
SyntaxError: invalid syntax
insert_osm_data.py is intended to be used with Python 2, but you are apparently running it under Python 3. The easiest fix is to install and use a Python 2 interpreter (compared to rewriting the script for Python 3 compatibility).
I myself is a beginner, but the much I am from the error, it looks like there is a syntax error in you file, as you are using python 3 you should use this : print('node not found: '+ str(node)) in line 160 in you file insert_osm_data.py . In python 3 if you print statement is turned into a print() function.

Categories