今天在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. Linux Centos安装及卸载Apache

    一.卸载 1.查看有没有安装apache,出现下面信息则安装过 [root@localhost ~]# rpm -qa|grep httpd httpd-2.2.15-53.el6.centos.x8 ...

  2. 分组查询限制。HAVING可写在GROUP BY前。

    限制一.无GROUP BY时统计函数不能和字段同时出现: 限制二.有GROUP BY时字段部分只能出现分组的字段: 限制三.统计函数嵌套时不能有字段.

  3. for循环语句以及输出语句

    action() { int  i;  //定义变量    lr_start_transaction("submit_answer");  //开始事物    for(i=0; i ...

  4. Qt之移动硬盘热插拔监控

    最近在做一个通用对话框,类似于windows的资源管理器,当然了没有windwos资源管理器那么强大.用户报了一个bug,说通用对话框打开之后不能实时监控U盘插入,随手在百度上搜索了一圈,这个问题还是 ...

  5. 关于mysql的loose index scan的几点疑问

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/102 关于MySQL的loose index scan有几点疑问 ...

  6. NP完整性| 集1(简介)

    我们一直在写关于高效算法来解决复杂问题,如最短路径,欧拉图,最小生成树等.这些都是算法设计者的成功故事. 在这篇文章中,讨论了计算机科学的失败故事. 计算机可以解决所有的计算问题吗? 存在计算问题,即 ...

  7. 简单工厂(Simple Factory),最合适的设计模式首秀.

    简单工厂又称为静态工厂方法(static factory method)模式,简单工厂是由一个工厂来决定创建出哪一种个体的实现,在很多的讨论中,简单工厂做为工厂方法模式(Factory Method) ...

  8. 第六节 etc/passwd 、etc/shadow 、 useradd 、 groupadd

    调优方法原理:禁用atime的修改来节省cpu和内存资源.命令:mount noatime disk 1.配置文件1. /etc/passwd文档结构:由":" 分隔成7个字段&q ...

  9. lambda表达式不使用委托(delegate) 用FUNC

    lLambda不使用delegate关键字,而使用  Lambda运算符 => goes to l    1.Func<int,string> getInput = (int age ...

  10. VMware_ubuntu设置共享文件夹

    1. 点击安装VMware tools 2.将/media/vmtool的压缩包复制到/home/pc/vm_tool下,应为原路径在root权限下竟然也是只读的,并且无法更改. 3.进入/home/ ...