Executing the sh file or running the project --dataset: command not found and SyntaxError: EOL while scanning string literal

–dataset: command not found

My mistake or how to solve it

The original shell file content

python main.py 
  --phase train \
  --dataset_name day-night \
  --lambda_A 1000.0 \
  --lambda_B 1000.0 \
  --epoch 1000 \
  --GAN_type wgan

changed to

python main.py --phase train --dataset_name day-night --lambda_A 1000.0 --lambda_B 1000.0 --epoch 1000 --GAN_type wgan

can

In general, or the main cause of error

In fact, the parameter is not added. The code has the following requirements, so it must be added, unless you have a default value

insert image description here

Add –dataset to the Parameters in the picture below in pycharm.
insert image description here
If it is a shell file, the same is true

SyntaxError: EOL while scanning string literal

My mistake

print("Hello World!')

Good guy, can’t you see it?
I also Baidu for a long time, and then I accidentally discovered that in the print, there are double quotation marks in front and single quotation marks in the back. This is the problem.
changed to

print("Hello World!")

That's right

Secondly, the most likely reason for the problem is that the code splicing path in windows is prone to this error

This is because the string in python cannot end with \. If you want to break the line when the string is too long in python, you can use a backslash to break the line, so the backslash cannot be immediately followed by the quotation mark at the end of the string.
For example, path = r'D:\code\git\’ + image_name
when running like this, an error will be reported.

The solution to this is also very simple
Method 1: Use os.path.join

path = os.path.join(r'D:\code\git', image_name)

Method 2: The backslash of the path is escaped instead of r

path = 'D:\\code\\git\\' + image_name

Method 3: Format String

dirname="test"
path = r'D:\code\git\%s' % (image_name)  # 第一种格式化方法
#从 python 2.6 开始
path = r'D:\code\git\{}'.format(image_name) # 第二种格式化方法

Method 4: string interpolation (string interpolation)

# python 3.6 开始 支持string interpolation
image_name= "test"
path3 = rf'D:\code\git\{
      
      image_name}' 

Reference https://cloud.tencent.com/developer/article/1649026

Not to mention double quotes in front and single quotes in the back, such as

The \ line break in the shell file keeps the continuous symbols removed and changed to a space instead of a line break

Guess you like

Origin blog.csdn.net/weixin_42455006/article/details/127018448