Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
DAAS: DAAS (short for Data As A Service) is a “central repository”/”cloud strategy” that facilitates on-demand accessibility of business-critical data by an organization’s users in a timely manner.


#tech_term #DAAS
What is the difference between the below exceptions:

try:
// Your code block
except:
// Your exception block

Vs:

try:
// Your code block
except Exception:
// Your exception block

A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to `except BaseException:`).

NOTE: When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause.

A better try & except:

try:
import platform_specific_module
except ImportError:
platform_specific_module = None

#python #PEP8 #try #except #try_except #exception
Does that happen for you too, to CD into a wrong directory and need to get back to the previous directory?

Let's say you are in a long path like /mnt/new_volume/backup/files/archive, now you switch to home of your directory. In order to get back to the previous directory, you just need to issue the below command:

cd -

#linux #cd
What do you think the best way is to extract active users from the list below in Python?

users = [
{
"email":"ali@gmail.com",
"is_active":True
},
{
"email":"mohi@gmail.com",
"is_active":True
},
{
"email":"reza@live.com",
"is_active":False
},
{
"email":"marziyeh@gmail.com",
"is_active":False
}
]

Waiting for the answers :)

#python #question
In axigen mail server you can set a filter that if sender email address (from) has a specific text using regexp then redirect it to
another mailbox:

Security and Filtering -> Acceptance and Routing -> Advanced settings -> Add acceptance / routing rule

Phew! Now in Conditions section open combo box and select Email under Recipient. Click Add condition. A text box is appeared now which you can select Regexp from the combo box and enter your regex like:

.*SpecificSender.*

Now in actions section in name enter the mail address you want to receive emails in and in Folder text box enter INBOX.

This is it.

#mail #mail_server #axigen #filter #routing
In MongoDB you can compare one field to another using $expr:

db.users.find({ $expr: { $eq: ["$created_at", "$updated_at"] } })

Here we get users that their updated_at field is equal to created_at field, here it means that user has not yet updated his profile.

#mongodb #mongo #expr #find
What is filters in Python Logging and what we can do with it?

Filter is a way to tell logger not to log or to log something. Let's say you print sensitive data in a core module that can also handle passwords. Here you don't want to record user passwords in you logs! Do you?!

class NoPasswordFilter(logging.Filter):
def filter(self, record):
return not record.getMessage().startswith('password')

logger.addFilter(NoPasswordFilter())

The above method will not log lines which start with password. You can use regex to find your template in you logs and return false
to not record them or mask the password part by chaning the the log using:

record.msg

Just get your message using the above line and replace it with something you want.

#python #logging #filter
# How to merge two dictionaries
# in Python 3.5+

>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 3, 'c': 4}

>>> z = {**x, **y}

>>> z
{'c': 4, 'a': 1, 'b': 3}

# In Python 2.x you could
# use this:
>>> z = dict(x, **y)
>>> z
{'a': 1, 'c': 4, 'b': 3}

# In these examples, Python merges dictionary keys
# in the order listed in the expression, overwriting
# duplicates from left to right.