How to fix syntax error at semicolon before equal - python

I am running a code taken from the website
http://foreverlearning.altervista.org/genetic-programming-symbolic-regression-pt-2/
at the bottom of the page. This is a part when testing treeOperations.py.
To test this code, I run the mainprova.py code that is provided at the bottom of the page after treeOperations.py listing. I am getting the following syntax error:
python mainprova3.py
Traceback (most recent call last):
File "mainprova3.py", line 2, in <module>
import treeOperations as trop
File "/home/adam/DocumentsNew2/MathCode/SymbolicRegression/WebpageCode /treeOperations.py", line 23
if choice <= leftNodes:
^
SyntaxError: invalid syntax
I am new to python. I do not understand the semicolon before equal sign. What it means? How do I fix it?

< is the HTML entity for <. There is apparently some sort of bug in the linked site that is causing things to be HTML-escaped that shouldn't be. Replace <= with <=.

You apparently copied the code from the GitHub page while looking at the html. Try just cloning the project:
git clone https://github.com/fabiochiusano/SymbolicRegressionPy.git
Or, if you don't have git, look at the file in 'raw' and then save it, instead of copying it off the nicer-looking page. For example, like this: https://raw.githubusercontent.com/fabiochiusano/SymbolicRegressionPy/master/symreg/treeOperations.py

You can go here: https://github.com/fabiochiusano/SymbolicRegressionPy
and click on clone or download > Download zip to download all the correct code files at once.

Related

How to get past the AttributeError in Gnu Radio version 3.8

Here is the error I am recieving:
Traceback (most recent call last):
File "/home/awilhelmy5/Downloads/qpsk-adaptive-master/gnuradio/qpsk_usrp.py", line 354, in <module>
main()
File "/home/awilhelmy5/Downloads/qpsk-adaptive-master/gnuradio/qpsk_usrp.py", line 332, in main
tb = top_block_cls()
File "/home/awilhelmy5/Downloads/qpsk-adaptive-master/gnuradio/qpsk_usrp.py", line 148, in __init__
self.mapper_preamble_sync_demapper_hard_0 = mapper.preamble_sync_dehard(0, per_bits, mapper.QPSK, [0,1,3,2], 0, 3, False)
AttributeError: module 'mapper' has no attribute 'preamble_sync_dehard'
The very last line of the error is the part that is bugging me. I have tried a multitude of things, such as installing swig version 4.0, tried doing the sudo ldconfig command, tried reversing the order of the commands in the .h file, I changed the yml file name to match the name it had in the xml file and I even started messing around with the target_link
_libraries command. Any help would be greatly appreciated!
Is it possible that your code has an error (e.g. accidental deletion of some characters)? I ask because I was not able to find the text "preamble_sync_dehard" anywhere on the web, but there is a class called gr::mapper::preamble_sync_demapper_hard. Perhaps some person or program did an unwise find-and-replace that intended to remove a prefix mapper_ but ended up removing a substring instead. You can check whether this is the problem: run Python and enter
import mapper
dir(mapper)
This will list all the names in the Python module, one of which (if this is the only problem) will be preamble_sync_demapper_hard, or some related spelling which you can then adjust your qpsk_usrp.py to use.
But if it is not there at all, then you may have a bigger problem. From what I have heard, OOT modules generally have to have their structure updated in order to work with GNU Radio 3.8, and the repository I found doesn't seem to have been touched since 2018 (before 3.8 was released in 2019).

Syntax error when trying to open a file through Python 3 Command Shell

So I am learning Python through Udemy tutorials and now I need to open a file through CMD(CMD is opened on folder I need) and when I am typing function for opening file it says syntax error, but I have made everything good what a guy on tutorials says, I really don't know what what should I do, I checked all of the forums and still cant find the answer.
Here are some screenshots:
Couple of issues:
1.Your text file is called "example.txt.txt" instead of "example.txt"
2.The "example.txt","r" should be surrounded with brackets () instead of <>. These symbols look similar in cmd and are easy to confuse.
#instead of
file = open<"example.txt","r">
#use
file = open("example.txt","r")
This should fix your problem; let me know if it does.
You have to use parenthesss () not <>
file = open("example.txt","r")
check https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

Python - L error in declaration

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

Inconsistent file behavior

I'm trying to track down a Python UnicodeDecodeError in the following log line:
10.210.141.123 - - [09/Nov/2011:14:41:04 -0800] "gfR\x15¢\x09ì|Äbk\x0F[×ÐÖà\x11CEÐÌy\x5C¿DÌj\x08Ï ®At\x07å!;f>\x08éPW¤\x1C\x02ö*6+\x5C\x15{,ªIkCRA\x22 xþP9â\x13h\x01­¢è´\x1DzõWiË\x5C\x10sòʨR)¶²\x1F8äl¾¢{ÆNw\x08÷#ï" 400 166 0.000 "-" "-"
I opened the entire log file in Vim, and then yanked the line into a new file so I could test just the one line. However, my parsing script works OK with the new file - it doesn't throw a UnicodeDecodeError. I don't understand why the one file would generate an error and the other one would not, when they are (on the surface) identical.
Here's what I tried: running enca to determine the file encoding, which complained that it Cannot determine (or understand) your language preferences. file -i says that both files are Regular files. I also deleted every other line in the original log file and still got the error in one file and no error in the other. I tried deleting
set encoding=utf-8
from my .vimrc, writing the file again, and I still got the error in one file and not in the other.
The logs are nginx logs. Nginx has this note in their release notes:
*) Change: now the 0x00-0x1F, '"' and '\' characters are escaped as \xXX
in an access_log.
Thanks to Maxim Dounin.
My Python script has with open('log_file') as f and the error comes up when I try to call json.dumps on a dict.
How can I track this down?
Your question: How can I track this down?
Answer:
(1) Show us the full text of the error message that you got -- without knowing what encoding that you were trying to use, we can't tell you anything. A traceback and a snippet of code that reads the file and reproduces the error would also be handy.
(2) Write a tiny Python script to find the line in the file and then do:
print repr(the_line) # Python 2.X
print ascii(the_line) # Python 3.x
and copy/paste the result into an edit of your question, so that we can see unambiguously what is in the line.
(3) It does look like random gibberish except for the ­ but do tell us whether you expect that line to be text (if so, in what human language?).

Python - Error Parsing HTML w/ BeautifulSoup

I'm developing an app that inputs data onto a webpage shopping cart and verifies the total. That works fine, however, I am having issue with parsing the HTML output.
A previous discussion; retrieving essential data from a webpage using python, recommended using BeautifulSoup to make solve said user's problem.
I've borrowed some of the python code, and got it to work on a MacOS system. However when I copied the code over to an ubuntu installation, I'm seeing a strange error.
**The Code (where I'm seeing the issue):
response = opener.open(req)
html = response.read()
doc = BeautifulSoup.BeautifulSoup(html)
table = doc.find('tr', {'id':'carttablerow0'})
dump = [cell.getText().strip() for cell in table.findAll('td')]
print "\n Catalog Number: %s \n Description: %s \n Price: %s\n" %(dump[0], dump[1], dump[5])
**The Error ( on the ubuntu server)
Traceback (most recent call last):
File "./shopping_cart_checker.py", line 49, in <module>
dump = [cell.getText().strip() for cell in table.findAll('td')]
TypeError: 'NoneType' object is not callable
I think I've narrowed it down to getText() being the culprit. But I'm not certain why this works on MacOS and not ubuntu.
Any suggestions?
Thank you.
#########################
Hi Guys,
Thank you for the various suggestions. I've attempted most of them, (incorporating the "if cell" statement into the code, however it still isn't working.
# Ignacio Vazquez-Abrams -- Here's a copy of the HTML I'm attempting to strip:
http://pastebin.com/WdaeExnC
As to why it doesn't work on Ubutntu, no idea. However, you can try this:
dump = [(cell.getText() if cell.getText() else '').strip() for cell in table.findAll('td')]
It doesn't seem to be a problem with the code but with the HTML you are reading, what I would do is changing your code to do this:
dump = [cell.getText().strip() for cell in table.findAll('td') if cell]
That way if cell is None it will not try to execute getText and just skip that cell. You should debug if you can, i recommend you to use pdb or ipdb (the one i like to use). Here is a tutorial, with that you can stop just before the line and print values, etc.

Categories