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
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!
Read More:
- Type error: sequence item 0: expected STR instance, int found
- Expected STR instance, float found
- Error casting p_sequencer, please verify that this sequence/sequence item is intended to execute
- Python: How to Fix “Ord() expected string of length 1, but int found”
- Error lnk2038: detected “0”_ ITERATOR_ DEBUG_ The reason and solution of the unmatched item of “level”
- Can’t multiply sequence by non int of type ‘float’
- pthread_ Introduction and application of join function
- Windows 10 startup item repair an operating system was’t found solution
- ERROR:expected initializer before “int”
- C++: terminate called after throwing an instance of ‘std::length_error‘ (sort function cmp sorting rules problem)
- IBM MQ Reason 2538(MQRC_ HOST_ NOT_ An example of error reason
- make Error: error: cast from ‘int32_t*’ {aka ‘int*’} to ‘int’ loses precision [-fpermissive]
- Found item Attr/circleRadius more than one time
- error 1962:no operating system found.boot sequence will automatically repeat.
- error Expected an assignment or function call and instead saw an expression
- Pychar appears“ PEP:8 expected 2 blank lines ,found 1″
- C# Member XXX cannot be accessed with an instance with an instance reference;qualify it with a type
- Windows 10 startup item repair an operating system wasn’t found
- java.lang.IllegalArgumentException : could not get next sequenced ID for sequence name: Visitor solution
- [Fixed] Error:(3) Error retrieving parent for item: No resource found that matches the given name ‘android’