Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 26 days ago.
Improve this question
JSONDecodeError: Expecting ':' delimiter: line 1 column 8388729 (char 8388728)
import json
with open('tweets.json') as jfile:
d = json.load(jfile)
i tried using this code.but it did not work.
this is the sample data
enter image description here
The error shows that your json data is not valid. There must be some syntax error in the json data. Specifically, it seems that there is a problem with the delimiter (':') at the specified line and column number.
You can use any JSON validator to find out the issue.
You can try this or
this with a pretty formatter
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
This post was edited and submitted for review 3 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I'm trying to save a text from python but it generates strange characters "\u00f1" and I don't know how to eliminate this
This is the code I'm using:👇
with open("NoticiasHabboHotel.json", "w") as f:
json.dump(test_versions, f, indent=0, separators=(',', ': '))
This is the text that generates me:
Dise\u00f1adores de salas, \u00a1os necesitamos!27345
What I want is to convert it into normal letters
I have tried different methods, such as encoding="utf8" and it doesn't work
Could someone help me, thank you very much!
See: https://docs.python.org/3/library/json.html#basic-usage
You need to add ensure_ascii=False because ñ is a non-ASCII character
with open("NoticiasHabboHotel.json", "w") as f:
json.dump(test_versions, f, indent=0, separators=(',', ': '), ensure_ascii=False)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I have the input like this
8.8.8.8,678,fog,hat
8.8.4.4,5674,rat,fruit
www.google.com,1234,can,zone
I want to split this input in Python so that only the IP address needs to be fetched which I will use for PING purpose. I really appreciate your help in this regard.
Guessing that your input is in a .csv file.
You could use Pandas or built in csv library to parse it. Using the latter in the example below.
import csv
with open("my_input.csv") as file:
csv_reader = csv.reader(file, delimiter=",")
ip_adresses = [ip for ip, *_ in csv_reader]
print(ip_adresses)
>> ['8.8.8.8', '8.8.4.4', 'www.google.com']
I collect the first item of the each row by using list unpacking.
Let's say one line of your data is in a variable called line. Then you can get the ping address this way:
ping = line.split(',')[0]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to add a error message if it exceeds 12 or if a character is entered without any if statements. here is what I have written so far:
import calender
def get_mont_name(month_number):
try:
return calender.month_name[month_number]
except IndexError:
print("'[]' is not a valid month number".format(month_number))
Your code is really close to working!
Firstly, you've spelt calendar wrong, but I assume this is just a typo.
You've slightly misused format() which is probably causing your issue. Replacing your print statement with the following should fix it:
print("{num} is not a valid month number".format(num = month_number))
The curly brackets allow the format() method to identify the parts of the string you'd like to modify.
I hope this helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a text file where I wrote a list of symbolic equations. I need to set the value of a variable with this list.
In other words I'm looking for a command that automatically "copy" all I have written in the text file and "paste" it into an expression such this:
a = all_it's_written_in_the_text_file
Is this possible?
with open(filename, "rt") as f:
a = eval(f.read())
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to write a regex, that will traverse through my file and replace each :
href='#!/api/API.
with
href='http://www.domain.com/API. . I currently have this kind of code, that will be run from console :
def replace(file, pattern, substring):
my_file = open(file)
for line in my_file:
my_file.write(line.replace(pattern, substring))
Will sending the given strings work in this case ?
So you want to replace #!/api with http://www.domain.com?
You can just do:
line.replace('#!/api','http://www.domain.com')
No need for regex.