Rajendra Dharmkar has Published 452 Articles

How not to match a character after repetition in Python Regex?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 08-Sep-2023 13:14:59

239 Views

Regex, short for regular expression, is a powerful tool in Python that allows you to perform complex text pattern matching and manipulation. It's like a Swiss Army knife for string handling, enabling you to slice, dice, and reconfigure text with finesse. However, when it comes to matching characters after repetition, ... Read More

How does [d+] regular expression work in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 08-Sep-2023 13:12:32

2K+ Views

Regular expressions are an essential tool for searching and manipulating strings in Python. Among the various patterns and techniques available, the [d+] expression is particularly useful for matching one or more digits in a string. In this article, we will explore the [d+] regular expression pattern, its usage, and provide ... Read More

How can I make one Python file run another?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 02-Sep-2023 12:38:01

54K+ Views

It is not unusual to come across situations in Python coding where you may need one Python script to execute another. Here, in this article, we will discuss and explore four different approaches to perform this task with ease and efficiency. As you will see, you will be guided through ... Read More

How to retrieve source code from Python objects?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 31-Aug-2023 02:44:11

13K+ Views

Using the inspect module, you can retrieve the source code of a Python function, method, class, or module. The following example demonstrates how to retrieve a function's source code − Example import inspect def my_function(x, y): return x + y source_code = inspect.getsource(my_function) print(source_code) Output def ... Read More

How can a Python function return a function?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 31-Aug-2023 02:34:02

15K+ Views

Python supports first-class functions. In fact, all functions in python are first- class functions. Python may return functions from functions, store functions in collections such as lists and generally treat them as you would any variable or object. A function can return a function in Python because functions are treated ... Read More

How to open a file in the same directory as a Python script?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 28-Aug-2023 13:50:51

27K+ Views

It is an accepted fact that file handling is a fundamental operation in programming. And Python provides a broad set of tools to handle file operations so as to interact with files. Oftentimes, when working with Python scripts, it may be required to open a file located in the same ... Read More

How to import a Python module given the full path?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 28-Aug-2023 13:15:13

23K+ Views

It is a recurrent and routine task of file handling in Python where there are solutions for different tasks of file processing. One such scenario is where you are required to import a module from a certain location on your system. Python's has appropriate tools to provide for dynamically importing ... Read More

What are .pyc files in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 27-Aug-2023 12:13:53

31K+ Views

In Python, .pyc files are compiled bytecode files that are generated by the Python interpreter when a Python script is imported or executed. The .pyc files contain compiled bytecode that can be executed directly by the interpreter, without the need to recompile the source code every time the script is ... Read More

What is PYTHONPATH environment variable in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 26-Aug-2023 08:50:16

36K+ Views

In Python, PYTHONPATH is an environment variable that specifies a list of directories to search for Python modules when importing them. When you import a module in Python, Python looks for the module in the directories specified in sys.path, which is a list of directories that includes the current working ... Read More

How do I convert a datetime to a UTC timestamp in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 26-Aug-2023 08:21:46

33K+ Views

You can use the datetime module to convert a datetime to a UTC timestamp in Python. If you already have the datetime object in UTC, you can the timestamp() to get a UTC timestamp. This function returns the time since epoch for that datetime object. If you have the datetime ... Read More

Previous 1 ... 4 5 6 7 8 ... 46 Next
Advertisements