48
Indentation changes itself when copying the code from the Editor into Python 3.13.1 results in IndentationError · Issue #129489 · python/cpython · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a kind of beginner with Python and the following issue happened:
I have a code to extract information from a search engine and when I try to copy my code into Python 3.13.1 it destroy the intendation and I get the IndentationError.
And when I copy it into Python somehow the intendation will be destroyed and I got the IndentationError, because the
else:
results.append({'Company Name': company, 'Website': None})** 2 lines have more blank space then it should have to have.
So the code will look like this:
Python 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
I tried to write the code with Notepad, Notepad++ and VisualBasic and it happened everytime I copied the code into Python 3.13.
Next to it I have been trying to write the code directly into Python 3.13. and it started to run without letting me to finish the code.
Op. system: Windows
The text was updated successfully, but these errors were encountered:
F3 key not worked, however I used Visualstudio to edit the code then run from cmd the script and then fixed an error in the Visualstudio and saved and run again with/from cmd and worked. Here is the description for the solution I found out and used: #124096 (comment)
Hi,
I am a kind of beginner with Python and the following issue happened:
I have a code to extract information from a search engine and when I try to copy my code into Python 3.13.1 it destroy the intendation and I get the IndentationError.
import pandas as pd
import requests
import os
Load the input file
input_file = 'companies.csv'
df = pd.read_csv(input_file)
Your SerpAPI key
SERPAPI_KEY = 'PUT YOUR SERPAPI_KEY HERE'
base_url = 'https://serpapi.com/search'
Create a list to hold results
results = []
Loop through each company name and fetch website
for company in df['Company Name']:
params = {
'api_key': SERPAPI_KEY,
'engine': 'google',
'q': company,
'hl': 'en',
'gl': 'us'
}
response = requests.get(base_url, params=params)
data = response.json()
if 'organic_results' in data and len(data['organic_results']) > 0:
website = data['organic_results'][0].get('link')
results.append({'Company Name': company, 'Website': website})
else:
results.append({'Company Name': company, 'Website': None})
Create a DataFrame and save to CSV
results_df = pd.DataFrame(results)
results_df.to_csv('company_websites.csv', index=False)
And when I copy it into Python somehow the intendation will be destroyed and I got the IndentationError, because the
else:
results.append({'Company Name': company, 'Website': None})**
2 lines have more blank space then it should have to have.
So the code will look like this:
Python 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
I tried to write the code with Notepad, Notepad++ and VisualBasic and it happened everytime I copied the code into Python 3.13.
Next to it I have been trying to write the code directly into Python 3.13. and it started to run without letting me to finish the code.
Op. system: Windows
The text was updated successfully, but these errors were encountered: