今天在cmd中用Python写第一行代码“Hello World”出现错误。

写好的源码“HelloWorld.py”存放于“ F:\learning\python test ”文件夹中。 最开始我写的代码:C:\Users\lenovo>python HelloWorld.py

然后出现如下错误:

错误原因:想在命令行中运行py文件需要写上完整的py文件目录,我在Users\lenovo中执行 “python HelloWorld.py”在当前目录下是找不到这个文件的。 解决办法:1. 切换到HelloWorld.py所在的目录下;2.给该文件的目录写完整。

Solution 1:切换到HelloWorld.py所在的目录下

C:\Users\lenovo>f:

F:\>cd learning\python test

F:\learning\python test>python HelloWorld.py

得到的结果如下:

ps: cd 的意思是“切换目录”。

疑问:为什么不能在第一行“C:\Users\lenovo>”处直接切换到F盘, 例如:C:\Users\lenovo>f:\learning\pythontest 或者 C:\Users\lenovo>cd f:\learning\pythontest ? (此处已把“python test”文件夹中的空格符去掉了,见Solution 2) 如下图:

Solution2:给该文件的目录写完整

C:\Users\lenovo>python f:\learning\pythontest\HelloWorld.py

得到的结果如下:

注:此时文件夹的名字已由“python test”改为“pythontest”。

如果中间的空格不去掉,会得到如下结果:

so 为什么中间的空格会影响打印结果 ?

btw,如果不调用Python直接输入“HelloWorld.py”, 也能打印出正常结果,为什么这个不需要指明路径也能打印出结果来 ? 如下图所示。

Waiting for the coming training.

Mistakes in Hello World的更多相关文章

  1. 【转载学习前辈的经验】-- Mistakes I made (as a developer) 我(作为一名开发者)所犯过的错误

    我 2006 年开始工作,至今已经 10 年.10 年是个里程碑,我开始回顾自己曾经犯过的错误,以及我希望从同行那里得到什么类型的忠告.一切都在快速改变,10 年了,我不能确定这些秘诀是否还有用. 不 ...

  2. 10 Biggest Business Mistakes That Every Entrepreneur Should Avoid

    原文链接:http://www.huffingtonpost.com/syed-balkhi/10-biggest-business-mista_b_7626978.html When I start ...

  3. [转]50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs

    http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/ 50 Shades of Go: Traps, Gotc ...

  4. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题

    E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  5. [TypeScript] 1. Catching JavaScript Mistakes with TypeScript

    The TypeScript compiler is a powerful tool which catches mistakes even in vanilla JavaScript. Try it ...

  6. Top 10 Mistakes Java Developers Make--reference

    This list summarizes the top 10 mistakes that Java developers frequently make. #1. Convert Array to ...

  7. HDOJ/HDU 1161 Eddy's mistakes(大写字母转换成小写字母)

    Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for e ...

  8. Yet Another 10 Common Mistakes Java Developers Make When Writing SQL (You Won’t BELIEVE the Last One)--reference

    (Sorry for that click-bait heading. Couldn’t resist ;-) ) We’re on a mission. To teach you SQL. But ...

  9. 5 Common Interview Mistakes that Could Cost You Your Dream Job (and How to Avoid Them)--ref

    There have been many articles on our site on software testing interviews. That is because, we, as IT ...

  10. hdu1161Eddy's mistakes

    Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for e ...

随机推荐

  1. Mybatis(基于SqlSessionTemplate的实现) + Spring 练习实战

    mybatis学习篇:上次使用映射接口实现Mybatis,有不方便指出就是需要接口,且需要保证接口上不能存在其他的代理.这次通过SqlSessionTemplate基于模板类实现Mybatis,总的来 ...

  2. iOS 让图片变模糊

    #import <Accelerate/Accelerate.h> 1.初始化图片 UIImageView *iv = [[UIImageView alloc]initWithFrame: ...

  3. Pytorch windows10安装教程

    强烈建议安装anaconda之后再来安装这个pytorch,具体怎么安装百度搜索就知道了. 温馨提示,在安装anaconda的时候记得将"添加到环境变量"(安装的时候是英文的)这一 ...

  4. NOI 2009 诗人小G

    题目描述 Description 小G是一个出色的诗人,经常作诗自娱自乐.但是,他一直被一件事情所困扰,那就是诗的排版问题. 一首诗包含了若干个句子,对于一些连续的短句,可以将它们用空格隔开并放在一行 ...

  5. 获取数据库时间sql 以及行级锁总结-共享锁-排他锁-死锁

    --TRUNC(date,[fmt]) /TRUNC(number[,decimals])SELECT SYSDATE FROM dual;SELECT TRUNC(SYSDATE) FROM dua ...

  6. lesson - 4 笔记 /inode / suid / sgid / sbit / chmod /umask / chown / rwx / wc /grep / tr / sort / cut /which / whereis / locate / find / ln /

    一.帮助+基本文件管理+用户管理 1.怎么查看命令帮助 ls --help man ls :查看命令/man 5 file:查看配置文件 二.基本文件管理,通过{查,建,删,改} 四个维度介绍了不同的 ...

  7. ADB 安卓开发配置环境

    下载完后将名称中含有adb的文件,和fastboot.exe复制到 c:/windows/system32目录 或c:/windows/system64目录(看自己电脑系统配置 如电脑64操作系统就写 ...

  8. oracle 导入 dmp

    执行命令 imp his/his@orcl File=/home/oracle/core_his50_common.dmp FULL=Y

  9. 解决adb push时出现的"Read-only file system"问题

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  10. IDA Pro反编译代码类型转换参考

    /* This file contains definitions used by the Hex-Rays decompiler output. It has type definitions an ...