michaelliao / learn-python3 Goto Github PK
View Code? Open in Web Editor NEWLearn Python 3 Sample Code
License: GNU General Public License v2.0
Learn Python 3 Sample Code
License: GNU General Public License v2.0
按照老师讲的方法,第一步,将notepad++的格式转变为UTF-8 without BOM
第二步,在代码前面加上# -- coding: utf-8 --
在做《字符串和编码》的练习时,中文输出还是二进制
是否我的计算机默认语言设置有问题?
代码如下:
s1=72
s2=85
r=(s2-s1)/s1*100
print ('the percentage: %.1f%%' % r)
在cmd界面调用后:
C:\work>python percent.py
Traceback (most recent call last):
File "percent.py", line 5, in
print ('\u767e\u5206\u6bd4\u4e3a: %.1f%%' % r)#show xx.x%, %%means showing one %
File "C:\Users\paris\AppData\Local\Programs\Python\Python35\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-3: character maps to
进行TCP编程 sever和client简单通信。
运行程序一直:
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
请问怎么解决?
谢谢
运行learning.py有什么用呢?做什么用的?一直没理解,烦请解释一下,初学者。。。
I am using Kali Linux virtual machine to do some pentesting and see if my Windows virtual machine was vulnerable. I am trying to get data using my Kali Linux virtual Machine but I am not receiving any data from the Windows virtual machine. Can someone tell me how I should edit my Python code to get data from my Windows virtual machine? Thank you.
I am a beginner in python 3
I need course pyhon3
Py
to learn
is it possible to convert language into English
Leaning python
Operation result:b'-Err Syntax error
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import copy
def YH_triangles(line):
originList=[] #initial empty list
resultList=[] #initial empty list
for i in range(line):
originList.append(0)
for j in range(i+1):
if j==0 or j==i:
originList[j]=1
else:
originList[j]=resultList[j-1]+resultList[j]
resultList=copy.deepcopy(originList) #deepcopy to resultList
yield resultList
queue is imported while Queue is used, when you try get result from queue for 11 times the error will be threw.
do_logging.py中
logging.info('n==%d' % n) 警告提示
应改为 logging.info('n==%d', n)
系统:win10,编辑器:pycharm,版本:Python3.7
C:\ProgramData\Anaconda3\python.exe C:/仙女莉/Python学习/start.py
Traceback (most recent call last):
File "C:/仙女莉/Python学习/start.py", line 17, in
server = smtplib.SMTP(smtp_server, 25) # SMTP协议默认端口是25
File "C:\ProgramData\Anaconda3\lib\smtplib.py", line 261, in init
fqdn = socket.getfqdn()
File "C:\ProgramData\Anaconda3\lib\socket.py", line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte
下面是源码:
from email.mime.text import MIMEText
msg = MIMEText('hello, send by Python...', 'plain', 'utf-8')
from_addr = input('From: ')
password = input('Password: ')
to_addr = input('To: ')
smtp_server = input('SMTP server: ')
import smtplib
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()
pop3可以正常下载邮件,代码运行正常,但是执行完解析邮件的代码没有任何反应,没有报错,然而也没有任何输出,一脸懵逼,这是神马情况?
return s and s.strip()
这个应该如何理解呢?and在这里的作用是什么呢?为何不能是
return s.strip()
搜索到了原因:
https://stackoverflow.com/questions/45799757/why-does-return-s-and-s-strip-work-when-using-filter
import time
from datetime import datetime as dt
host_temp="D:\python work\blolcker"
hosts_path=r"C:\Windows\System32\drivers\etc\hosts"
redirect="127.0.0.1"
website_list=["www.facebook.com","facebook.com"]
while True:
if dt(dt.now().year,dt.now().month,dt.now().day,8) <dt.now() < dt(dt.now().year,dt.now().month,dt.now().day,12):
print("working hours...")
with open(hosts_path,"r+") as file:
content = file.read()
for website in website_list:
if website in content:
pass
else:
file.write(redirect+" "+website+"\n")
else:
with open(hosts_path,"r+") as file:
content = file.readlines()
file.seek(0)
for line in content:
if not any(website in line for website in website_list):
file.write(line)
file.truncate()
print("you are free")
time.sleep(5)
关于用生成器找素数的这个问题, 代码逻辑很清楚 但是电脑怎么跑不出来?求解答
我是小白,不会玩。去哪里入门。
按照recur.py里面的code照搬,运行出来的结果和网页中写的期待结果不一样。
在登陆 廖雪峰官方网站 https://www.liaoxuefeng.com/auth/signin 时只能使用微博登陆,这比较尴尬。不经常玩微博,也不想注册微博账号,希望可以其它方式登陆,如QQ号码登陆,微信登陆,或者本网站注册账号登陆可否?
个人爱好,刚刚开始学习编程。。。。
想把汉诺塔每一步前面加上行动序号
def mov(n,a,b,c,count):
if n==2:
print("step %d :%s-->%s" % (count,a,b))
count=count+1
print("step %d :%s-->%s" % (count,a, c))
count = count + 1
print("step %d :%s-->%s" % (count,b, c))
count = count + 1
return count
elif n>2:
count=mov(n-1,a,c,b,count)
print("step %d :%s-->%s" % (count,a,c))
count = count +1
count=mov(n-1,b,a,c,count)
return count
------------------------------------------分割线------------------------------------
from Hannoi import mov
count=1
mov(10,"A","B","C",count)
------------------------------------------分割线------------------------------------
试了一下,貌似可以运行,求大神改进,谢谢赐教!
I need to learn Python
ModuleNotFoundError: No module named 'ConfigParser'
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jv/wm0988950n9ggzpj52kfkn3c0000gn/T/pycharm-packaging/MySQL-python/
第67行代码未定义charset导致有中文值的环境变量无法正常显示。(Chrome 版本 58.0.3029.110 (64-bit))
# diff:
67- start_response('200 OK', [('Content-Type', 'text/html')])
67+ start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
第70行<p>
元素未闭合。
#diff:
70- p = '<p>%s = %s' % (k, str(v))
70+ p = '<p>%s = %s</p>' % (k, str(v))
建议将教材整理到gitbook.
我启动后,访问不了,怎么回事?
1.Hi Developers im new to coding. i tried to make this video uploading app to my firebase storage but im not that good at coding so im stuck at this problem. when upload button is pressed the filechooser is opened and if i select a file it gets uploaded to the firebase But if i cancel and close the filechooser it gives an error.
2. i am unaware if this file chooser works on android or nor...if it does not please help me with this code too. im stuck on this since 6 January ,thats how poor i am.
from kivy.app import App
from kivy.lang import Builder
kv = '''
<MainScreen>:
name: 'mainscreen'
MDLabel:
id:username_info
text:'Hello Main'
font_style:'H1'
halign:'center'
MDFloatLayout:
id:floate
Video:
id:vid
MDToolbar:
title: 'Bottom navigation'
md_bg_color: .2, .2, .2, 1
specific_text_color: 1, 1, 1, 1
MDBottomNavigation:
panel_color: 1,1,1,1
MDBottomNavigationItem:
name: 'screen 1'
text: 'Home'
icon: 'home-outline'
MDRaisedButton:
id:upload
text:'Upload'
pos_hint:{'center_x':.5, 'center_y':.4}
on_release:
app.file_chooser()
upload.disabled=False
'''
class goodApp(MDApp):
def build(self):
self.strng = Builder.load_string(help_str)
self.url = "link.json"
return self.strng
def file_chooser(self):
filechooser.open_file(on_selection=self.selected)
def selected(self,selection):
config={
'Api keys of firebase'
}
firebase=pyrebase.initialize_app(config)
storage=firebase.storage()
Directory=selection[0]
Name=re.findall('[ \w-]+\..*',Directory)
loginEmail = self.strng.get_screen('loginscreen').ids.login_email.text
storage.child(str(f"{loginEmail}")).child(str(f"{Name}")).put(str(f"{Name[0]}"))
if selection==True:
self.root.ids.vid.source=firebase
self.strng.get_screen('mainscreen').ids.upload.disabled=True
self.strng.get_screen('mainscreen').manager.current ='uploadscreen'
self.strng.get_screen('mainscreen').manager.transition.direction='left'
if selection==False:
self.strng.get_screen('mainscreen').ids.upload.disabled=False
if __name__ == '__main__':
goodApp().run()
[INFO ] [Logger ] Record log in C:\Users\Dheeraj.kivy\logs\kivy_22-01-19_1.txt
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO ] [Kivy ] v2.0.0
[INFO ] [Kivy ] Installed at "C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\kivy_init_.py"
[INFO ] [Python ] v3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Users\Dheeraj\AppData\Local\Programs\Python\Python38\pythonw.exe"
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [KivyMD ] 0.104.2, git-bc7d1f5, 2021-06-06 (installed at "C:\Users\Dheeraj\AppData\Local\Programs\Python\Python38\lib\site-packages\kivymd_init_.py")
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used
[INFO ] [GL ] OpenGL version <b'2.1 Mesa 10.0.2 (git-675cd84)'>
[INFO ] [GL ] OpenGL vendor <b'VMware, Inc.'>
[INFO ] [GL ] OpenGL renderer <b'Gallium 0.4 on llvmpipe (LLVM 3.4, 128 bits)'>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b'1.30'>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [KivMob ] init called.
[WARNING] [KivMob ] Ads will not be shown.
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Video ] Provider: null(['video_ffmpeg', 'video_ffpyplayer'] ignored)
[INFO ] [Base ] Start application main loop
Traceback (most recent call last):
File "C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\plyer\platforms\win\filechooser.py", line 102, in run
self.fname, _, _ = win32gui.GetOpenFileNameW(**args)
pywintypes.error: (0, 'GetOpenFileNameW', 'No error message is available')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\plyer\platforms\win\filechooser.py", line 108, in run
self._handle_selection(self.selection)
File "C:\Users\Dheeraj\Desktop\kivy codes\priyanshu doraming\Magenta.py", line 949, in selected
Directory=selection[0]
IndexError: list index out of range
[INFO ] [Base ] Leaving application in progress...
Add images to explain us this bug. Paste urls here.
Remove this section if no images here
Traceback (most recent call last):
File "task_master.py", line 22, in
manager.start()
File "...\multiprocessing\managers.py", line 479, in start
self._process.start()
File "...\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "...\multiprocessing\context.py", line 313, in _Popen
return Popen(process_obj)
File "...\multiprocessing\popen_spawn_win32.py", line 66, in init
reduction.dump(process_obj, to_child)
File "...\multiprocessing\reduction.py", line 59, in dump
ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <function at 0x00594CD8>: attribute lookup on main failed
这是怎么回事
Ping - s 9000 (ip s)
learn-python3/samples/oop_advance/orm.py
Line 64 in ec95ecf
该实现,一个 User
对象,似乎只能对应生成一条插入。
没必要用 SQL 的问号语法( values (?,?,?,?)
)吧?
learn-python3/samples/async/async_wget2.py
与 learn-python3/samples/async/async_hello2.py
Cool learning
async_wget2.py的内容竟然跟async_hello2.py 一模一样~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.