pythonjam怎么安装库_JamCh01

JamCh01 回答了问题 · 2018-12-28

在Python3.5中已经提供了type hints功能In [1]: def greeting(name: str) -> str:

...: return 'Hello ' + name

...:

...:

In [2]: greeting(name=1)

---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in ()

----> 1 greeting(name=1)

in greeting(name)

1 def greeting(name: str) -> str:

----> 2 return 'Hello ' + name

TypeError: must be str, not int

在Python3.5中已经提供了type hints功能 {代码...}

关注 6回答 5

JamCh01 回答了问题 · 2018-12-28

我觉得不是p定义的位置,如果报错是:An attempt has been made to start a new process before the

current process has finished its bootstrapping phase.

This probably means that you are not using fork to start your

child processes and you have forgotten to use the proper idiom

in the main module:

if __name__ == '__main__':

freeze_support()

...

The "freeze_support()" line can be omitted if the program

is not going to be frozen to produce an executable.

那这么修改就可以啦~import multiprocessing

import time

import os

import random

def worker(msg):

start_time = time.time()

print("开始执行进程 %d ----- %s" % (msg, os.getpid()))

time.sleep(random.random() * 2)

stop_time = time.time()

print(msg, '耗费时间是 %0.2f' % (stop_time - start_time))

def main():

multiprocessing.freeze_support()

pool = multiprocessing.Pool()

cpus = multiprocessing.cpu_count()

[pool.apply_async(worker, args=(i, )) for i in range(0, cpus)]

pool.close()

pool.join()

if __name__ == '__main__':

main()

我觉得不是p定义的位置,如果报错是: {代码...} 那这么修改就可以啦~ {代码...}

关注 4回答 2

JamCh01 关注了问题 · 2018-12-26

页面中的弹窗,隐藏在本页面中的div中,只有点击鼠标,才会弹出

用requests 怎么才能获取到这个弹出的窗口信息

关注 2回答 2

JamCh01 回答了问题 · 2018-12-25

In [1]: import sys

In [2]: sys.path

Out[2]:

['',

'D:\\Program Files\\Python36\\Scripts\\ipython.exe',

'd:\\program files\\python36\\python36.zip',

'd:\\program files\\python36\\DLLs',

'd:\\program files\\python36\\lib',

'd:\\program files\\python36',

'C:\\Users\\Jam\\AppData\\Roaming\\Python\\Python36\\site-packages',

'd:\\program files\\python36\\lib\\site-packages',

'd:\\program files\\python36\\lib\\site-packages\\win32',

'd:\\program files\\python36\\lib\\site-packages\\win32\\lib',

'd:\\program files\\python36\\lib\\site-packages\\Pythonwin',

'd:\\program files\\python36\\lib\\site-packages\\IPython\\extensions',

'C:\\Users\\Jam\\.ipython']

In [3]: sys.path.append('test')

In [4]: sys.path

Out[4]:

['',

'D:\\Program Files\\Python36\\Scripts\\ipython.exe',

'd:\\program files\\python36\\python36.zip',

'd:\\program files\\python36\\DLLs',

'd:\\program files\\python36\\lib',

'd:\\program files\\python36',

'C:\\Users\\Jam\\AppData\\Roaming\\Python\\Python36\\site-packages',

'd:\\program files\\python36\\lib\\site-packages',

'd:\\program files\\python36\\lib\\site-packages\\win32',

'd:\\program files\\python36\\lib\\site-packages\\win32\\lib',

'd:\\program files\\python36\\lib\\site-packages\\Pythonwin',

'd:\\program files\\python36\\lib\\site-packages\\IPython\\extensions',

'C:\\Users\\Jam\\.ipython',

'test']

list的append不会又返回值,会直接操作list

{代码...} list的append不会又返回值,会直接操作list

关注 2回答 1

JamCh01 赞了回答 · 2018-12-20

1.首先关于 is ,如楼上所说的,is 判断两个变量是否指向内存的同一区域,也即变量的 id 是否相同。

2.题主需要了解一下 小整数对象池 的概念。因为一般情况下,程序中小整数 [-5, 256] 的使用是比较频繁的,python 为了优化速度,建立了 小整数对象池,也就是说这些小整数在内存中是唯一的。因此:a = 1

b = 1

a is b # True

a, b 都是小整数,其对应相同的内存,也就是说变量的id是相同的,所以 a is b 返回 True。

而对于浮点数,每建立一个新的变量就开辟一块内存,所以 a = 1.1 和 b = 1.1 指向的内存地址是不同的,因此 a is b 返回 False 。

2.题主需要了解一下 小整数对象池 的概念。因为一般情况下,程序中小整数 [-5, 256] 的使用是比较频繁的,python 为了优化速度,建立了 小整数对象池,也就是说这些小整数在内存中是唯一的。因此:

关注 4回答 3

JamCh01 赞了回答 · 2018-12-17

a = int(a)

b = int(b)

c = int(c)

其实我很想知道你如何验证

{代码...} 其实我很想知道你如何验证

关注 1回答 1

JamCh01 评论了文章 · 2018-12-14

superjamc

图片源于网络,仅参考 无须过于较真。

引言:早上起来就看到朋友圈都在发这个,也不知道是真是假,慌的一B~

图中的 c 表示已被确认,大家可以看到各个大厂真的是在大幅度裁员。

不知道明年的情况会如何,网上看到过一句话:2019 年也许是这 10 年最差的一年,但可能是接下来 10 年中最好的一年。

欢迎大家可以在留言区说出你想说的。查看原文

图片源于网络,仅参考 无须过于较真。 引言:早上起来就看到朋友圈都在发这个,也不知道是真是假,慌的一B~ 图中的 c 表示已被确认,大家可以看到各个大厂真的是在大幅度裁员。 不知道明年的情况会如何,网上看到过一句话:2019 年也许是这 10 年最差的一年,但可能...

JamCh01 回答了问题 · 2018-12-13

In [1]: '%2Fkns%2Fbrief%2Fbrief.aspx%3Fcurpage%3D17%26RecordsPerPage%3D20%26QueryID%3D0%26'.lower()

Out[1]: '%2fkns%2fbrief%2fbrief.aspx%3fcurpage%3d17%26recordsperpage%3d20%26queryid%3d0%26'

In [2]: import re

In [3]: regex = re.compile(r'%\d{1}[A-Z]{1}')

In [4]: _ = '%2Fkns%2Fbrief%2Fbrief.aspx%3Fcurpage%3D17%26RecordsPerPage%3D20%26QueryID%3D0%26'

In [5]: res = regex.findall(_)

In [6]: res

Out[6]: ['%2F', '%2F', '%2F', '%3F', '%3D', '%3D', '%3D']

In [7]: for i in res:

...: _ = _.replace(i, i.lower())

...:

In [8]: _

Out[8]: '%2fkns%2fbrief%2fbrief.aspx%3fcurpage%3d17%26RecordsPerPage%3d20%26QueryID%3d0%26'

{代码...}

关注 2回答 1

JamCh01 回答了问题 · 2018-12-12

先说一个问题,这种大厂的URL往往对应了很多个IP地址,如果不介意这一点,那么可以这样做。

构建一个函数,函数的参数是URL地址,返回地市信息。

解析这个文件,提取URL,存入列表。

获得返回值写文件。

假设第二步和第三步你已经完成,那么:import aiohttp

import asyncio

import aiofiles

async def foo(url):

params={'url': url}

async with aiohttp.ClientSession() as session:

async with session.get(url='http://httpbin.org/get', params=params):

pass

if __name__ == "__main__":

urls = list()

loop = asyncio.get_event_loop()

tasks = [foo(url=url) for url in urls]

loop.run_until_complete(asyncio.wait(tasks))

loop.close()

先说一个问题,这种大厂的URL往往对应了很多个IP地址,如果不介意这一点,那么可以这样做。构建一个函数,函数的参数是URL地址,返回地市信息。解析这个文件,提取URL,存入列表。获得返回值写文件。假设第二步和第三步你已经完成,那么:

关注 4回答 2

JamCh01 回答了问题 · 2018-12-12

这个问题其实是yield和return有什么不同的区别,return不必多讲,肯定明白。所以这个问题变成了yield是什么。

在进入正文之前可能需要明白是什么是生成器,在生成器之前,你需要明白的是什么是迭代。

迭代

假如一个列表,他就是可迭代对象,在Python里面叫做Iterable。In [1]: _list = [1, 2, 3]

In [2]: for i in _list:

...: print(i)

...:

1

2

3

可迭代对象如果觉得比较抽象,可以打比方讲,可迭代的就是“一排东西”。比如列表,字符串等等。

生成器

生成器当然也是可以迭代的,但是只能读取一次,因为它的值并不存在与内存中(实时生成)。In [5]: _generator = (x**x for x in range(1, 4))

In [6]: for i in _generator:

...: print(i)

...:

1

4

27

In [7]: for i in _generator:

...: print(i)

...:

yield

yield是与return类似的作用,但yield只返回的是一个生成器。但是在Scrapy中对一个列表进行抓取经常会用到for循环。当然了下面的只是一个例子。In [10]: def foo():

...: _list = range(4)

...: for i in _list:

...: yield i

...:

In [11]: gen = foo()

In [12]: gen

Out[12]:

In [13]: for i in gen:

...: print(i)

...:

0

1

2

3

In [14]: for i in gen:

...: print(i)

...:

你只需要明白在在调用foo的时候,函数内部不会立即执行,只是返回了一个生成器对象。在迭代的时候函数会开始执行,当在yield的时候,会返回当前值(i)。之后的这个函数会在循环中进行,直到没有下一个值。In [15]: def foo():

...: _list = range(4)

...: print('run in func')

...: for i in _list:

...: print('run in loop')

...: yield i

...:

...:

In [16]: gen = foo()

In [17]: for i in gen:

...: print(i)

...:

...:

run in func

run in loop

0

run in loop

1

run in loop

2

run in loop

3

所以了~你应该明白Scrapy中的return与yield的区别了吧~

这个问题其实是yield和return有什么不同的区别,return不必多讲,肯定明白。所以这个问题变成了yield是什么。 在进入正文之前可能需要明白是什么是生成器,在生成器之前,你需要明白的是什么是迭代。 迭代 假如一个列表,他就是可迭代对象,在Python里面叫做Iterable...

关注 2回答 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值