Skip to content

Commit 85022fc

Browse files
OS Path
1 parent 7e79bf9 commit 85022fc

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

PythonFromScratch.ipynb

+172
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,178 @@
23632363
"tp[0] = ('b')"
23642364
]
23652365
},
2366+
{
2367+
"cell_type": "markdown",
2368+
"metadata": {},
2369+
"source": [
2370+
"# File Paths"
2371+
]
2372+
},
2373+
{
2374+
"cell_type": "code",
2375+
"execution_count": 8,
2376+
"metadata": {},
2377+
"outputs": [],
2378+
"source": [
2379+
"from os.path import basename, dirname, isfile, normpath, join\n",
2380+
"import os"
2381+
]
2382+
},
2383+
{
2384+
"cell_type": "code",
2385+
"execution_count": 1,
2386+
"metadata": {},
2387+
"outputs": [
2388+
{
2389+
"data": {
2390+
"text/plain": [
2391+
"'c:\\\\Users\\\\Anas\\\\Videos\\\\YOUTUBE\\\\imgs\\\\Python\\\\Tutorial'"
2392+
]
2393+
},
2394+
"execution_count": 1,
2395+
"metadata": {},
2396+
"output_type": "execute_result"
2397+
}
2398+
],
2399+
"source": [
2400+
"os.getcwd()"
2401+
]
2402+
},
2403+
{
2404+
"cell_type": "code",
2405+
"execution_count": 4,
2406+
"metadata": {},
2407+
"outputs": [
2408+
{
2409+
"data": {
2410+
"text/plain": [
2411+
"'c:\\\\Users\\\\Anas\\\\Videos\\\\YOUTUBE\\\\imgs\\\\Python'"
2412+
]
2413+
},
2414+
"execution_count": 4,
2415+
"metadata": {},
2416+
"output_type": "execute_result"
2417+
}
2418+
],
2419+
"source": [
2420+
"dirname(os.getcwd())"
2421+
]
2422+
},
2423+
{
2424+
"cell_type": "code",
2425+
"execution_count": 5,
2426+
"metadata": {},
2427+
"outputs": [
2428+
{
2429+
"data": {
2430+
"text/plain": [
2431+
"'Tutorial'"
2432+
]
2433+
},
2434+
"execution_count": 5,
2435+
"metadata": {},
2436+
"output_type": "execute_result"
2437+
}
2438+
],
2439+
"source": [
2440+
"basename(os.getcwd())"
2441+
]
2442+
},
2443+
{
2444+
"cell_type": "code",
2445+
"execution_count": 6,
2446+
"metadata": {},
2447+
"outputs": [
2448+
{
2449+
"data": {
2450+
"text/plain": [
2451+
"False"
2452+
]
2453+
},
2454+
"execution_count": 6,
2455+
"metadata": {},
2456+
"output_type": "execute_result"
2457+
}
2458+
],
2459+
"source": [
2460+
"isfile(os.getcwd())"
2461+
]
2462+
},
2463+
{
2464+
"cell_type": "code",
2465+
"execution_count": 13,
2466+
"metadata": {},
2467+
"outputs": [
2468+
{
2469+
"data": {
2470+
"text/plain": [
2471+
"'c:\\\\Users\\\\Anas\\\\Videos\\\\YOUTUBE\\\\imgs\\\\Python\\\\Tutorial\\\\text.txt'"
2472+
]
2473+
},
2474+
"execution_count": 13,
2475+
"metadata": {},
2476+
"output_type": "execute_result"
2477+
}
2478+
],
2479+
"source": [
2480+
"join(\"c:\\\\Users\\\\Anas\\\\Videos\\\\YOUTUBE\\\\imgs\\\\Python\\\\Tutorial\", 'text.txt')"
2481+
]
2482+
},
2483+
{
2484+
"cell_type": "code",
2485+
"execution_count": 12,
2486+
"metadata": {},
2487+
"outputs": [
2488+
{
2489+
"name": "stdout",
2490+
"output_type": "stream",
2491+
"text": [
2492+
"anas\\azdad\n"
2493+
]
2494+
}
2495+
],
2496+
"source": [
2497+
"print(\"anas\\\\azdad\")"
2498+
]
2499+
},
2500+
{
2501+
"cell_type": "code",
2502+
"execution_count": 23,
2503+
"metadata": {},
2504+
"outputs": [
2505+
{
2506+
"name": "stdout",
2507+
"output_type": "stream",
2508+
"text": [
2509+
"b'Hello World !'\n"
2510+
]
2511+
}
2512+
],
2513+
"source": [
2514+
"with open(join(r\"c://\\Users//Anas//Videos//YOUTUBE//imgs//Python//Tutorial\", 'text.txt'), 'rb') as f:\n",
2515+
" print(f.read())"
2516+
]
2517+
},
2518+
{
2519+
"cell_type": "code",
2520+
"execution_count": 25,
2521+
"metadata": {},
2522+
"outputs": [
2523+
{
2524+
"data": {
2525+
"text/plain": [
2526+
"'c:\\\\Users\\\\Anas\\\\Videos\\\\YOUTUBE\\\\imgs\\\\Python\\\\Tutorial\\\\text.txt'"
2527+
]
2528+
},
2529+
"execution_count": 25,
2530+
"metadata": {},
2531+
"output_type": "execute_result"
2532+
}
2533+
],
2534+
"source": [
2535+
"normpath(join(r\"c://\\Users//Anas//\\/\\\\//Videos//YOUTUBE//imgs//Python//Tutorial\", 'text.txt'))"
2536+
]
2537+
},
23662538
{
23672539
"cell_type": "code",
23682540
"execution_count": null,

text.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World !

0 commit comments

Comments
 (0)