社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

AKX

AKX 最近创建的主题
AKX 最近回复了
4 年前
回复了 AKX 创建的主题 » python将unicode代码值转换为字符串,不带“\u”

您可以使用常规的列表理解来映射中的4个字符 text ,并使用 ord 得到 奥德 码点的最后一个(整数),然后 hex() 将其转换为十六进制。这个 [2:] 需要切片来去除 0x 否则Python会添加。

>>> text = "\u54c8\u54c8\u54c8\u54c8"
>>> text
'哈哈哈哈'
>>> [hex(ord(c))[2:] for c in text]
['54c8', '54c8', '54c8', '54c8']
>>>

然后你可以使用。 "".join() 如果你需要一根绳子。

(另一种写理解的方法是使用f字串和 x 十六进制格式:

>>> [f'{ord(c):x}' for c in text]
['54c8', '54c8', '54c8', '54c8']

)

如果你 事实上 有一根绳子 \u54c8\u54c8\u54c8\u54c8 ,即“反斜杠,u,5,4,c,8”重复4次,您需要首先解码反斜杠转义序列以获得4码点字符串:

>>> text = r"\u54c8\u54c8\u54c8\u54c8"
>>> codecs.decode(text, "unicode_escape")
'哈哈哈哈'

你可以用 zip() .

>>> arr1 = [[1,2,3], [5,6,7]]
>>> [b - a for (a, b) in zip(*arr1)]
[4, 4, 4]

( zip(*x) 是一个有用的习语,通常用来转置一个可数的可数,即turn [[1, 2, 3], [5, 6, 7]] [[1, 5], [2, 6], [3, 7]] .)

3 年前
回复了 AKX 创建的主题 » 无法安装pycrypto,python 3.10,如何修复?

我敢打赌缺少了什么,或者Pycrypto的版本在64位Windows上的Python 3.10上不起作用。(Pycrypto自2013年以来就没有更新过。你可能不想使用它。)

你能做你想做的事吗 cryptography ,即。 pip install cryptography ? 似乎有预编配的Windows控制盘。

还有一个叉子 pycryptodome , pycryptodomex ,这可能会有帮助。

3 年前
回复了 AKX 创建的主题 » 如何使用Python从数组中找到完整的单词(带空格)?

你有太多了 str() 向四周施压,使最初的 if 子字符串搜索。

尝试

array = ['finance', 'healthcare', 'information technology', 'government', 'textile', 'petroleum']

user_response = str(...)  # wherever you get the input from

# If you don't cast `array` to a string, 
# Python will just try to find the string in the list; 
# otherwise it does a substring search.

if user_response in array:
   # ...
else:
   print("Give valid answer")
5 年前
回复了 AKX 创建的主题 » 表架构名称与Django中的数据模型类名不匹配

Django数据库表被命名为 <app>_<model> .

你的应用程序名是 user User ,因此自动生成的名称是 user_user .

class User(model.Model):
    class Meta:
        db_table = 'user'
5 年前
回复了 AKX 创建的主题 » Python 3为什么不返回[duplicate]

当你递归调用 gcd

def gcd(a, b):
    if a == 0 or b == 0:
        return max(a, b)
    else:
        if a > b:
            return gcd(a - b, b)
        else:
            return gcd(b - a, a)
5 年前
回复了 AKX 创建的主题 » Python/Tkinter-总和标签

你需要使用 DoubleVar.get() 要访问包含的值:

def calc():
    v_result.set(float(e_entry.get()) * 10 / 100)
    v_result2.set(float(e_entry2.get()) * 10 / 100)
    v_result3.set(float(v_result.get() + v_result2.get()))

def calc():
    # Read...
    v1 = round(float(e_entry.get()), 1)
    v2 = round(float(e_entry2.get()), 1)

    # Compute...
    result = v1 + v2

    # Write...
    v_result.set(v1)
    v_result2.set(v2)
    v_result3.set(result)
6 年前
回复了 AKX 创建的主题 » python的pipenv安装包不工作

pip 实际上是在提醒你这件事。。。

脚本virtualenv-clone.exe安装在不在路径上的“C:\Users\andri\AppData\Roaming\Python\Python37\Scripts”中。 考虑将此目录添加到路径。。。 脚本virtualenv.exe安装在不在路径上的“C:\Users\andri\AppData\Roaming\Python\Python37\Scripts”中。 考虑将此目录添加到路径。。。 脚本pipenv-resolver.exe和pipenv.exe安装在不在路径上的“C:\Users\andri\AppData\Roaming\Python\Python37\scripts”中。 考虑将此目录添加到路径。。。

您需要添加该目录

C: \Users\andri\AppData\Roaming\Python\Python37\脚本

到您的PATH环境变量;有很多方法可以做到,请参见。 Adding directory to PATH Environment Variable in Windows

另一种选择是总是使用

C:\...> C:\Users\andri\AppData\Roaming\Python\Python37\Scripts\pipenv install

但我认为这可能会很快变得有点陈腐。

5 年前
回复了 AKX 创建的主题 » 如何使用Python类并请求用户输入?

如果您来自Java背景,那么应该知道,除非您需要由 self .

无论如何,你看到的错误是因为你的方法没有被标记 @classmethod @staticmethod 因此需要类的一个实例,而您只是通过类本身调用它们(因此没有隐式实例或类对象作为第一个参数传入)。

因此,您的选择是:

1创建的实例 Arithmetic() 使用它:

arith = Arithmetic()
n1 = arith.float_input("Enter your First number: ")
n2 = arith.float_input("Enter your Second number: ")

2将方法标记为静态的,例如。

@staticmethod
def float_input(prompt):  # note: no `self`

3标记方法类方法,例如。

@classmethod
def float_input(cls, prompt):  # `cls` is `Arithmetic` (or its subclass) itself

4使方法只是没有类的正则函数。

5 年前
回复了 AKX 创建的主题 » 从csv列表加速Python请求

像这样的事情应该能让你得到多个处理的工作。

其思想是将作业从CSV重构为一个生成器函数,然后将访问API的函数重构为另一个生成器函数。

(因为你显然是在窗户上,所以你需要使用 main() 函数和 if main 守卫 multiprocessing .)

import requests
import csv
import multiprocessing

sess = requests.Session()

headers = {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Authorization": "Bearer *********",
    "Cache-Control": "no-cache",
    "Host": "*****",
}


def read_jobs():
    with open("C:\\******.csv") as csvfile:
        for row in csv.reader(csvfile, delimiter=","):
            yield row[0]


def get_job_status(job):
    url = (
        "https:/********.com/api/v1.0/companies/**/jobs/"
        + job
        + "?columns=Status"
    )
    response = requests.request(
        method="GET", url=url, headers=headers
    )
    print("Got job ", job)
    return (job, response.text)


def main():
    with open("C:\\*********another****.csv", "w") as outfile:
        with multiprocessing.Pool() as pool:
            for result in pool.imap_unordered(
                get_job_status, read_jobs()
            ):
                print(result, file=outfile)


if __name__ == "__main__":
    main()
5 年前
回复了 AKX 创建的主题 » Python上程序的错误操作,计算两个数字的和[重复]

input() 从Python 3开始始终返回字符串。

显式转换为整数:

a = int(input('a: '))
b = int(input('b: '))
print(a + b)
5 年前
回复了 AKX 创建的主题 » 如何提高python代码的时间效率?

您将希望将现有的数字转换为 int 埃格斯,然后把它们放在 set ;集合对于计算给定值是否为成员非常有效。

n = int(input())
extant = set(int(n) for n in input().split())
for i in range(1, n + 1):
    if i not in extant:
        print(i, end=" ")
6 年前
回复了 AKX 创建的主题 » 如何加速python中的脚本代码?

改变

patch_added = np.random.randn(patch.shape[0],patch.shape[1],patch.shape[2]) + patch

patch_added = np.zeros(patch.shape) + patch

将“时间消耗”减少到大约2秒,而不是10-11秒。

这意味着脚本大部分时间都在生成随机数。

6 年前
回复了 AKX 创建的主题 » 在python中对一堆值或列表进行整数运算?[复制品]

不管是numpy还是其他矢量化方法,您都在寻找列表理解。

arr = list(20,1,5,36,10,31,100)
quadrupled_arr = [x * 4 for x in arr]
6 年前
回复了 AKX 创建的主题 » 从php调用python脚本不起作用

我猜工作目录是错误的,你的脚本无法访问它需要的文件。

你可能想用

shell_exec("/home/amogh/server/test.py 2>&1");

为了将stderr重定向到stdout,因此python的任何错误输出也将在 $output 变量,以帮助您调试。

6 年前
回复了 AKX 创建的主题 » 为什么我不能安装mysqlclient==1.3.10

您需要mysql客户机库及其相关头文件。

这些是以BREW中的mariadb(mysql fork)包的形式提供的,因此 brew install mariadb 应该有技巧。

6 年前
回复了 AKX 创建的主题 » Django模型上的动态场

您可以添加 is_open

class RestaurantSerializer(serializers.HyperlinkedModelSerializer):
    is_open = serializers.SerializerMethodField()

    class Meta:
        model = Restaurant
        fields = ('pk', 'name', 'opening_time', 'closing_time', 'is_open')

    def get_is_open(self, instance):
        return instance.is_open
6 年前
回复了 AKX 创建的主题 » 为受保护的文件nginx和django提供服务

你的Django中没有捕获组 path 打电话到那里,这样只会匹配 /media/ 逐字的

你可能想利用旧学校 url 使用类似regexp的路由

urlpatterns += [
    url(r'/media/.+', serveMedia),
]

捕捉一切以 /媒体/

6 年前
回复了 AKX 创建的主题 » 如何使用setuptools将python标记添加到bdist_wheel命令?

你可以入侵类似的东西

if 'bdist_wheel' in sys.argv:
    if not any(arg.startswith('--python-tag') for arg in sys.argv):
        sys.argv.extend(['--python-tag', 'py36'])

但它也很脆弱…