Line of code changes when adding a new character

已回答

I have the following line:

csv_file.write(f'{v["id"]},{v["name"]},"{v["description"]}",{v["screensCount"]},{v["lastUsed"]["value"][:10]}')

But, when I add a character (next screenshot will show it), the line format changes and I can't find a way to stop this:

csv_file.write(f'{v["id"]},{v["name"]},"{v["description"]}",{v["screensCount"]},'
                           f'v{v["lastUsed"]["value"][:10]}')

*When I add any character, in this case the "v" marked under the red line, the strings changes and this is quite annoying.

How can I stop this from happening?

Thank you in advance.

0

Do you mean that the line break is added?

0

Hi Sergey, yes. This started since the last update and I haven't been able to find a root cause.

0

Do you have any 3rd party plugins installed?
If so, check if disabling them and restarting PyCharm helps.

If not, it would be great if you could provide an example code that I can use for reproducing the issue to investigate it further.

0

Hi Sergey,

No plugins. Just the Dracula Theme and I'm using the firacode fond with ligatures https://github.com/tonsky/FiraCode. However, I've been using this one since a couple of years and this is the first time happening.

This is the PyCharm version I'm using:

PyCharm 2023.1.2 (Community Edition)
Build #PC-231.9011.38, built on May 16, 2023
Runtime version: 17.0.6+10-b829.9 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1974M
Cores: 16
Registry:
    debugger.new.tool.window.layout=true
    ide.experimental.ui=true

Non-Bundled Plugins:
    com.vermouthx.idea (1.14.3)

Regarding the code (not the best code but does what I need), here it is:

import requests
from requests.auth import HTTPBasicAuth

######################################################################
# Enter your admin email, token and baseurl without the /
######################################################################
user = 'username'
token = 'token'
baseurl = 'URL'
######################################################################

auth = HTTPBasicAuth(user, token)

csv_file = open("cflist.csv", "a", encoding="utf-8")
csv_file.write("ID,Name,Description,Screens Count,Tracked?,Last Used")
csv_file.write("\n")

url_max = baseurl + '/rest/api/3/field/search'

headers = {
    'Accept': 'application/json',
    }

query = {
    'expand': 'lastUsed,screensCount'
}

response_max = requests.request(
        'GET',
        url_max,
        headers=headers,
        auth=auth
    ).json()['total']


i = 0

for i in range(response_max):
    url = url_max + '?maxResults=1' + '&startAt=' + str(i)

    response = requests.request(
        'GET',
        url,
        headers=headers,
        params=query,
        auth=auth
    )

    d = response.json()

    for v in d['values']:
        try:
            csv_file.write(f'{v["id"]},{v["name"]},"{v["description"]}",{v["screensCount"]},'
                           f'v{v["lastUsed"]["value"][:10]}')
            csv_file.write("\n")
            print(f'{i,v["id"]},{v["name"]},"{v["description"]}",{v["screensCount"]},{v["lastUsed"]["type"]},{v["lastUsed"]["value"][:10]}')
        except KeyError:
            csv_file.write(f'{v["id"]},{v["name"]},"{v["description"]}",{v["screensCount"]},{v["lastUsed"]["type"]}')
            csv_file.write("\n")
            print(f'{i,v["id"]},{v["name"]},"{v["description"]}",{v["screensCount"]},{v["lastUsed"]["type"]}')
            continue
csv_file.close()
0

I couldn't reproduce it.
Do you only type v letter before { and then it happens?

What is the value of Hard wrap at under File | Settings | Editor | Code Style | Python?

0

Hi Sergey,

The workaround, disabling the hard wrap, did the trick.

I thought it could be related to the wrapping but I couldn't find the option to disable it.

Regarding your question regarding the character, yes. But it wasn't just the v, it was any character. I would like to be able to use line wrapping anyway as it's quite helpful when working with long dictionaries but for now, this will do it.

 

Thank you very much for your help, I was getting quite frustrated when working with string formatting.

0

请先登录再写评论。