python - 命令提示符说文件存在时无法找到文件
问题描述
所以我有一个 .py 脚本,我试图在命令提示符或 anaconda 提示符下运行。如果我运行python filename.py
,它会给我这个错误:
python: can't open file 'C:\Users\tform\Documents\AirSim\CapstoneAPI.py': [Errno 2] No such file or directory
。
我不确定如何解决此问题,因为该文件位于该位置。我需要搞乱一些设置吗?
我使用 Visual Studio 2019 作为我的 Python IDE。
import os
import os.path
import csv
import datetime
import airsim
client = airsim.MultirotorClient()
client.confirmConnection()
'''
First create a directory for all the csv files to store into.
'''
dirmain = "C:\\AirSimData"
if not os.path.exists(dirmain):
os.mkdir(dirmain)
'''
Create base format for file names that specify date and time of run
'''
run_date_and_time = datetime.datetime.now()
run_date_and_time_string = run_date_and_time_string = run_date_and_time.strftime('%y-%m-%d_%H%M%S')
extension = ".csv"
file_name_base = run_date_and_time_string + extension
'''
Create each sensor type file names and join then to savepath
'''
imu = "imu"
gps = "gps"
magnetometer = "magnetometer"
barometer = "barometer"
gps_file_name = gps + file_name_base
gps_output_file= os.path.join(dirmain,gps_file_name)
imu_file_name = imu + file_name_base
imu_ouput_file = os.path.join(dirmain,imu_file_name)
mag_file_name = magnetometer + file_name_base
mag_ouput_file = os.path.join(dirmain,mag_file_name)
bar_file_name = barometer + file_name_base
bar_output_file = os.path.join(dirmain,bar_file_name)
gps_header = ['lat','lon','alt']
with open(gps_output_file,'w') as gpscsvfile:
gpscsvwriter = csv.writer(gpscsvfile)
gpscsvwriter = gpscsvwriter.writerow(gps_header)
while True:
gps_data = client.getGpsData().gnss.geo_point
alt = (gps_data.altitude)
lat = (gps_data.latitude)
lon = (gps_data.longitude)
gps_data_struct = [lat,lon,alt]
with open(output_file,'a') as gpscsvfile:
gpscsvwriter = csv.writer(gpscsvfile)
gpscsvwriter = gpscsvwriter.writerow(gps_data_struct)
imu_data = client.getImuData()
s = pprint.pformat(imu_data)
print("imu_data: %s" % s)
#print("Altitude: %s\nLatitude %s\nLongitude %s" %(alt,lat,lon) )
if False:
break
解决方案
推荐阅读
- swift - Casting JSON array to a struct model swift
- python - legend() 没有正确显示数据集
- python - 根据另一列的值提取一个csv列中的值
- c++ - 尝试删除链表时出现分段错误
- gatsby - 是否可以在 Gatsby matchPath 中使用通配符而不使用斜杠?
- javascript - 使用
使用 JavaScript 标记
- scala - 将进程标准输出传递给外部函数
- linux - How to see if a service is running on Linux?
- cloud - 云存储和云计算有什么区别?
- python - 基数为 10 的 int() 的无效文字:'first'