Tag Archives: Daily learning

Parse error in ubantu/Linux system [How to Solve]

Parse error in ubantu/Linux system

This problem took me some time. In order to avoid forgetting to post a blog in the future

Phenomenon:

The execution code and error reporting contents are as follows:

reason:

This is because the standard supported by the Linux gcc compiler is different from the current C89 standard. This C standard requires that the declaration of variables in a block be placed in front of all non declarative statements.

We can see that on line 266, a definition statement is placed before the declaration statement, so an error is reported

Solution:

Put 266 this non declarative statement under all declarative statements
as shown in the following figure:

the compilation succeeded without error, and the problem was solved successfully

The reason and solution of the error of join function: sequence item 0: expected STR instance, int found

When I was writing code the other day, the task was to separate the incoming parameters with “_” and then append them to the file
Direct up code

def operate(file_path, *args):
    f = open(file_path, mode="a", encoding="utf-8")
    s = ""
    s = '_'.join(args)
    f.write(s)
    f.flush()
    f.close()
operate("hhhh.txt", 123, 456, 789)

Receive a string, but I wrote a number by mistake, then reported an error
TypeError: sequence item 0: expected STR instance, int found TypeError: sequence item 0: expected STR instance, int found TypeError: sequence item 0: expected STR instance, int found
Then look for the document, and here’s the original text
Return a string which is the concatenation of the strings in iterable. A TypeError will be raised if there are any non-string values in iterable, including bytes objects. The separator between elements is the string providing this method.
The join function is a string function, and the arguments and inserts are strings
So:
S = ‘_’.join(args) to

s = '_'.join(str(args).strip())

That’s it!