惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
WordPress大学
WordPress大学
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
博客园 - Franky
D
Docker
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
U
Unit 42
M
MIT News - Artificial intelligence
B
Blog
GbyAI
GbyAI
C
Check Point Blog
P
Proofpoint News Feed
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
IT之家
IT之家
Google DeepMind News
Google DeepMind News
V
V2EX
Stack Overflow Blog
Stack Overflow Blog

博客园 - xiaobin80

Hello MFC - The last little bit of work Hello MFC - Add Resource and About Dialog Hello MFC - The Message Map my first mfc application Development Environment Preparation Clang IDE的选择在Windows Visual Studio 2017 and Fx EOL 跟我学python(5)- 匹配数字 跟我学python(4)- 正则 跟我学python(2)- 第一个程序 跟我学python --- 搭建开发平台 Debian server 安装 debian 与 ubuntu 之 - sudo Try Value 计算文件CRC32数值 docker ce on Debian 使用hugo在gitee上写blog spring cloud gateway - RequestRateLimiter postman使用 改进的冒泡算法 Create User - mysql COM调用 – VB、PB J-Link clone问题 修复山寨版的J-Link
跟我学python(3)--- 带shell功能的hello world
xiaobin80 · 2026-02-03 · via 博客园 - xiaobin80

1. 引入模块

import os

2. 使用判断

if expression :
   statement1
else :
   statement2

3. 使用模块

    1. 使用模块中的变量
os.name
    1. 使用模块中方法
os.system()

4. code

helloworld.py:

'''
Created on Dec 11, 2018

@author: xiaobin
'''
import os
'''
#! /usr/bin/perl
    $cmd="ls";
    system($cmd);
    ##chmod
    $myStr2 = 'world';
    print 'Hello $myStr2'."\n"
'''
cmd = "name"
if os.name == "nt" :
  cmd = "dir /w"
else :
  cmd = "ls -l"

print ('----'),
print (cmd),
print ('----')

os.system(cmd)

myStr2 = 'world'
print('Hello ' + myStr2)

5. 效果图

    1. windows
python.exe helloworld.py

command-prompt_out1

    1. WSL(ubuntu)

command-prompt_out2

Reference:

1. Python 条件语句