ورود

View Full Version : بک سوال درباره ی ماژول ونام برنامه



hisalam
شنبه 20 فروردین 1390, 03:43 صبح
سلام
چرا وقتی ماژولی رو به برنامه وارد می کنیم (مثلا یکی از ماژول های کتابخانه ی پایتون) در صورتی که همنام اون برنامه باشه موقع اجرا خطا می گیره؟؟؟

_______________
آقا حل شد

r00tkit
شنبه 20 فروردین 1390, 10:41 صبح
تست کردم خطا نگرفت مثال بزنی بهتره

hisalam
شنبه 20 فروردین 1390, 17:27 عصر
اینو به صورت md5.py ذخیره کن


import md5

password = raw_input("Enetr pass for encrypt : ")
hash = md5.new()
hash.update(password)
print hash.hexdigest()


فکر کنم فهمیدم چون کد واسطه می سازه باعث میشه خودش خودش رو import کنه ولی چرا؟؟؟

r00tkit
شنبه 20 فروردین 1390, 21:59 عصر
کدت اشتباه بود : import hashlib import os import sys m=hashlib.md5() #m.update(b"Nobody inspects") password = raw_input("Enetr pass for encrypt : ") m.update(password) print(m.hexdigest()) سرعتم کمه :(

hisalam
شنبه 20 فروردین 1390, 22:07 عصر
کدت اشتباه بود : import hashlib import os import sys m=hashlib.md5() #m.update(b"Nobody inspects") password = raw_input("Enetr pass for encrypt : ") m.update(password) print(m.hexdigest()) سرعتم کمه :(

دوست عزیز چی میگی
تو پایتون 2.7 (md5)این ماژول اضافه شده من همین رو به یه اسم دیگه ذخیره کردم به درستی هم اجرا شد




``md5`` --- MD5 message digest algorithm
****************************************

Deprecated since version 2.5: Use the ``hashlib`` module instead.

This module implements the interface to RSA's MD5 message digest
algorithm (see also Internet **RFC 1321**). Its use is quite
straightforward: use ``new()`` to create an md5 object. You can now
feed this object with arbitrary strings using the ``update()`` method,
and at any point you can ask it for the *digest* (a strong kind of
128-bit checksum, a.k.a. "fingerprint") of the concatenation of the
strings fed to it so far using the ``digest()`` method.

For example, to obtain the digest of the string ``'Nobody inspects the
spammish repetition'``:

>>> import md5
>>> m = md5.new()
>>> m.update("Nobody inspects")
>>> m.update(" the spammish repetition")
>>> m.digest()
'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d \xf0\xff\xe9'

More condensed:

>>> md5.new("Nobody inspects the spammish repetition").digest()
'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d \xf0\xff\xe9'

The following values are provided as constants in the module and as
attributes of the md5 objects returned by ``new()``:

md5.digest_size

The size of the resulting digest in bytes. This is always ``16``.

The md5 module provides the following functions:

md5.new([arg])

Return a new md5 object. If *arg* is present, the method call
``update(arg)`` is made.

md5.md5([arg])

For backward compatibility reasons, this is an alternative name for
the ``new()`` function.

An md5 object has the following methods:

md5.update(arg)

Update the md5 object with the string *arg*. Repeated calls are
equivalent to a single call with the concatenation of all the
arguments: ``m.update(a); m.update(b)`` is equivalent to
``m.update(a+b)``.

md5.digest()

Return the digest of the strings passed to the ``update()`` method
so far. This is a 16-byte string which may contain non-ASCII
characters, including null bytes.

md5.hexdigest()

Like ``digest()`` except the digest is returned as a string of
length 32, containing only hexadecimal digits. This may be used
to exchange the value safely in email or other non-binary
environments.

md5.copy()

Return a copy ("clone") of the md5 object. This can be used to
efficiently compute the digests of strings that share a common
initial substring.

See also:

Module ``sha``
Similar module implementing the Secure Hash Algorithm (SHA).
The SHA algorithm is considered a more secure hash.

hisalam
شنبه 20 فروردین 1390, 22:42 عصر
Deprecated since version 2.5: Use the ``hashlib`` module instead.

سلام ببخشید :قلب:دوست من
ولی من هنوز هم متوجه نمی شم
آخه من همون رو به اسم md5 ذخیره می کنم و بعد اجرا خطا می گیره ولی اگر اسمش رو md-5 بزارم نه اگه مشکلی تو سینتکس داشت که تو هیچ کدوم از حالت ها نباید درست اجرا میشد همونطور که گفتم گمون کنم بخاطر کد واسطه هست چون تو حالت دوم نمیسازه ولی اولی میسازه اگر هم باور نمی کنی یه فیلم بسازم

راستی اونکد تو مربوط به hashlib بود برای همین هم من ref رو گذاشتم
اون بالاهم نوشته که با 2.5 سازگار نیست و بجاش hashlib استفاده کن (یعنی تو نسخه 2.5 از Hashlib استفاده کن)در ضمن من دارم از 2.7 استفاده می کنم
در ضمن چرا پست قبلی رو ویرایش کردی بابا من که دشمنت نبودم:خجالت:

Mehdi Asgari
یک شنبه 21 فروردین 1390, 00:00 صبح
اینو ببین
http://docs.python.org/tutorial/modules.html#the-module-search-path
کاری که می کنی در پایتون ساپورت نمیشه