投稿時間:2023-07-30 18:17:59 RSSフィード2023-07-30 18:00 分まとめ(20件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita 【Twitter改めX】詐欺アカウント自動ブロックツール作成 https://qiita.com/nobukz/items/62b75e94cecb15d8278c twitter 2023-07-30 17:16:26
python Pythonタグが付けられた新着投稿 - Qiita 【Python】正規表現パターンに生文字列と通常の文字列を使う...機能に違いはあるのか? https://qiita.com/Ryo-0131/items/1ebc5d0b0e32c6b6e02b rawstring 2023-07-30 17:08:58
js JavaScriptタグが付けられた新着投稿 - Qiita Vue.jsで、リスト表示順の入れ替え処理を実装 https://qiita.com/76r6qo698/items/d396ad2174b6b0cf0095 vuejs 2023-07-30 17:18:22
js JavaScriptタグが付けられた新着投稿 - Qiita TypeScriptでマスターするGoFのファクトリパターン https://qiita.com/itinerant_programmer/items/0b92508d067f2c3d12ca gofgangoffour 2023-07-30 17:09:42
AWS AWSタグが付けられた新着投稿 - Qiita 【更新中】 https://qiita.com/kokichi8/items/b3cf8d1a84d3cab35e89 資料 2023-07-30 17:23:54
AWS AWSタグが付けられた新着投稿 - Qiita EC2 Instance Connectエンドポイント経由でWindows ServerにRDP接続してみた https://qiita.com/yokohama4580/items/0ea8840c90e4505ff93c ecinstanceconnect 2023-07-30 17:11:18
golang Goタグが付けられた新着投稿 - Qiita Go言語プログラムの資料を自動生成する https://qiita.com/tomtkg/items/073b90c7feaae45cd7db 面倒 2023-07-30 17:24:57
Azure Azureタグが付けられた新着投稿 - Qiita Teamsから社内利用できる、Web検索と独自データ検索付きのGPTボットを作る https://qiita.com/jw-automation/items/37de442bfed04d6a9e12 teams 2023-07-30 17:59:51
Azure Azureタグが付けられた新着投稿 - Qiita Azrue 仮想マシンスケールセットを試してみる https://qiita.com/watyanabe164/items/eb6cd0541e0cb33297cb azrue 2023-07-30 17:45:40
海外TECH DEV Community How to Use exec() in Python - Everything You Need to Know https://dev.to/sachingeek/how-to-use-exec-in-python-everything-you-need-to-know-380f How to Use exec in Python Everything You Need to KnowThe exec function in Python allows us to execute the block of Python code from a string This built in function in Python can come in handy when we need to run the dynamically generated Python code but it is recommended not to use it carelessly due to some security risks that come with it In this tutorial we ll be going to learnhow to work with Python s exec functionhow to execute Python code using the exec function with code examplesexecuting Python code from a string and Python source fileusing globals and locals parameters Python s exec functionPython s exec function allows us to execute any piece of Python code no matter how big or small that code is This function helps us to execute the dynamically generated code Think of a Python interpreter that takes the piece of code processes it internally and executes it the exec function does the same It is like an independent Python interpreter The exec is capable of executing simple Python programs as well as fully featured Python programs It can execute function calls and definitions class definitions and instantiations imports and much more Syntaxexec object globals locals object It must be a string or a code object If it is a string it is parsed as a suite of Python statements which is executed unless a syntax error occurs If it is a code object then it will simply execute globals and locals This allows us to provide dictionaries representing the global and local namespaces Return valueThe return value of the exec function is None It may be because every piece of code doesn t have the final result Initial glanceHere s an initial look at the working of the exec function obj apple cherry melon strawberry code print sliced for sliced in obj if a not in sliced exec code cher melo Another example of using the exec function The code will continuously run and we can run our code as we do in Python interpreter while True exec input gt gt gt gt gt gt print Welcome to GeekPython Welcome to GeekPython gt gt gt import numpy as np gt gt gt print np random randint size gt gt gt x apple banana cherry mango gt gt gt print fruit for fruit in x if a not in fruit cherry It works exactly like a Python interpreter taking our code processing it internally executing it and returning the correct results We re running an infinite loop and inside it we re taking input from the command line and wrapping it in the exec function to execute it Executing code from a string inputWe can use the exec function to execute the code which is in a string format There are multiple ways that we can use to build the string based input Using one liners codeUsing new line charactersUsing triple quoted strings with proper formatting Using one liner string based inputIn Python single line code also known as one liner code is code written in a single line that can perform multiple tasks at the same time If we wrote a single line of Python code it would look like this obj apple cherry melon strawberry print sliced for sliced in obj if a not in sliced Output cher melo But if we run the above code using the exec the code would beobj apple cherry melon strawberry exec print sliced for sliced in obj if a not in sliced OR exec code sliced for sliced in obj if a not in sliced The other code we wrote above will return nothing if we execute it instead the output will be stored in the code variable for later access Executing multiple lines of code separated by new line charactersWe can combine multiple statements in a single line string using the new line characters n exec square int input Enter the number nprint f The square of square square OutputEnter the number The square of A new line character n is defined to make the exec function understand our single line string based code as a multiline set of Python statements Using triple quoted stringIn Python we frequently use triple quotes to comment on or document our code However in this case we ll use it to generate string based input that looks and behaves exactly like normal Python code The code we write within triple quotes must be properly indented and formatted just like normal Python code See the example below for a better understanding sample code integers def square num return num def odd num num return num square if even square number for number in integers if number odd number number for number in integers if odd num number print Original values integers print Square of even number square if even print Odd number odd number exec sample code OutputOriginal values Square of even number Odd number The above code is similar to standard Python code with proper indentation and formatting but it is wrapped within triple quotes resulting in string based input stored in the sample code variable which was then executed using the exec function Executing code from a Python fileWe can use the exec function to execute the code from Python py source file by reading the content of the file using the open function Consider the following example which includes a sample py file containing the following code sample pydef anime name print f Favourite anime name anime One Piece list of anime input Enter your favourite anime split print Your Favourite anime list of anime The code simply prints the anime s name here while the following block of code takes the input of your favorite anime separated by commas and prints the desired output Executing the Python source file using the exec functionwith open sample py mode r as sample file sample read exec file OutputFavourite anime One PieceEnter your favourite anime One Piece Naruto Demon Slayer Jujutsu kaisenYour Favourite anime One Piece Naruto Demon Slayer Jujutsu kaisen We used the open function using the with statement to open the py file as a regular text file and then used the read on the file object to read the content of the file as a string into the file variable which is passed in the exec to execute the code Using globals and locals paramsThese parameters are entirely optional We can use globals and locals parameters to limit the use of functions methods and variables that aren t required Because these parameters are optional omitting them causes the exec function to execute the input code in the current scope Consider the following example to better understand it code out str strprint out global variablesstr Hel str lo exec code OutputHelloThe code above ran successfully and produced an output that combined both global variables Because the globals and locals parameters were not specified the exec function executed the code input in the current scope The current scope is global in this case Here s an example of how to get the value of a variable in the current scope of code code out str strprint out global variablesstr Hel str lo print out Traceback most recent call last NameError name out is not defined Did you mean oct In the preceding code we attempted to access the value of the out variable before calling exec and received an error However we can access the value of the out variable after calling exec because the variable defined in the code input will be available in the current scope after calling exec exec code print out OutputHelloHelloUsing globals and locals parameterscode out str strprint out global variablesstr Hel str lo exec code str str OutputTraceback most recent call last NameError name str is not defined Did you mean str The code returns an error because we didn t define the key holding the str in the dictionary so the exec doesn t have access to it code out str strprint out global variablesstr Hel str lo exec code str str str str print out OutputHelloTraceback most recent call last NameError name out is not defined Did you mean oct The exec function now has access to both global variables and the code returns the output without error but we didn t have access to the out after the call to exec this time because we re using the custom dictionary to provide an execution scope to the exec Here s an example of using locals and globals togethercode out str str xprint out global variablesstr Hel str lo def local local variable x there exec code str str str str x x local OutputHello thereIn the above code we called exec from within the local function In the global scope we have global variables and a local variable in the local scope function level The globals parameter specifies the variables str and str while the locals parameter specifies the variable x Blocking unnecessary methods and variablesUsing the globals and locals params we can control whether to restrict or use any variable or method in our code input In this section we ll limit some of the functions in Python s datetime module from datetime import code curr time datetime now print curr time exec code OutputTraceback most recent call last NameError name datetime is not definedWe restricted the use of the datetime method from the datetime module which resulted in an error Using necessary methods and variablesWe can only use the methods that are required with the exec from datetime import Allowing only two methodsallowed param datetime datetime timedelta timedelta exec print datetime now allowed param exec print datetime now timedelta days allowed param date method is not allowedexec print date allowed param Output Traceback most recent call last NameError name date is not definedThe error occurred because the date method was not permitted Except for two methods datetime and timedelta all methods in the datetime module were forbidden Let s see what else we can accomplish with globals and locals parameters from datetime import Setting globals parameter to builtins globals param builtins builtins Setting locals parameter to take only print slice and dir locals param print print dir dir slice slice exec print slice globals param locals param exec print dir globals param locals param Outputslice None None dir print slice Inside the exec function only the slice method and all built in methods can be executed Even though the slice method is not from the datetime module it works perfectly here We can also limit the use of builtins by setting it to None from datetime import Setting globals parameter to noneglobals param builtins None Setting locals parameter to take only print slice sum and dir locals param print print dir dir slice slice sum sum Allowed methods directoryexec print dir globals param locals param exec print f Sum of numbers sum globals param locals param Output dir print slice sum Sum of numbers We limited the use of builtins so we can t use the built in methods and can only execute the print sum slice and dir methods inside the exec ConclusionWe ve learned how to use the built in Python exec function to execute code from a string based input It allows you to run dynamically generated Python code The topics we ve learnedwhat is exec function and working with itexecuting Python code from a string based input and Python source filesunderstanding the use of the globals and locals parametersAdditionally we ve coded some of the examples which helped us understand the exec function better Other articles you might be interested in if you liked this oneHow to use assert statements to debug the code in Python Upload and display images on the frontend using Flask in Python Building a Flask image recognition webapp using a deep learning model What is generator and yield keyword in Python Public Protected and Private access modifiers in Python How to build a CLI command in a few steps using argparse in Python How to perform high level file operations using shutil module in Python How to scrape a webpage s content using BeautifulSoup in Python That s all for nowKeep Coding 2023-07-30 08:21:25
海外TECH DEV Community How to use DigitalOcean Spaces with Laravel Voyager? https://dev.to/bobbyiliev/how-to-use-digitalocean-spaces-with-laravel-voyager-4e35 How to use DigitalOcean Spaces with Laravel Voyager IntroductionDigitalOcean Spaces is an object storage service that allows you to store and serve large amounts of data It is a reliable and flexible solution for developers especially when integrated with Laravel Voyager a Laravel package that provides an admin interface with BREAD Browse Read Edit Add Delete operations media manager menu builder and much more This tutorial will guide you step by step on how to integrate DigitalOcean Spaces with Laravel Voyager Before we begin ensure you have a working Laravel application with Voyager installed We re also assuming that you have already created your DigitalOcean Space and have the necessary credentials Spaces Key Spaces Secret Spaces region Spaces Bucket and Spaces endpoint Laravel FilesystemLaravel provides a clean simple API over the popular Flysystem PHP package by Frank de Jonge The Laravel Flysystem integration provides simple to use drivers for working with local filesystems Amazon S and even FTP servers To utilize this feature for our purpose we need to install a specific package Step Installing the flysystem aws s v PackageThe DigitalOcean Spaces is compatible with the Amazon S API So we will use the flysystem aws s v package to interact with the DigitalOcean Spaces Open your terminal and navigate to the root directory of your Laravel project Now run the following command composer require league flysystem aws s vThis command will install the flysystem aws s v package which will allow us to interact with the DigitalOcean Spaces Step Configuring the File SystemIn the root directory of your Laravel application open the config filesystems php file Here we will add a new disk definition for spaces spaces gt driver gt s key gt env DO SPACES KEY secret gt env DO SPACES SECRET region gt env DO SPACES REGION bucket gt env DO SPACES BUCKET endpoint gt env DO SPACES ENDPOINT visibility gt public The visibility gt public setting is needed to ensure that the images uploaded via the media manager are visible to the public Next open the env file and add the following lines DO SPACES KEY your spaces key Example ABCDEFDO SPACES SECRET your spaces secret Example ABCDEFABCDEFABCDEFDO SPACES REGION your spaces region Example nycDO SPACES BUCKET your spaces bucket Example my bucketDO SPACES ENDPOINT your spaces endpoint Example Note that we didn t add the bucket name to the endpoint This is because the flysystem aws s v package will automatically append the bucket name to the endpoint Step Configuring VoyagerNow let s open the config voyager php file and update the storage disk to spaces storage gt disk gt spaces Step Overriding Default Voyager Blade View Optional In some older versions of Voyager the media manager view had some issues with the file path To verify if you are still affected by this issue visit the Voyager admin and if you see this error Found error while validating the input provided for the GetObject operation Key expected string length to be gt but found string length of The following steps will help you resolve this issue NOTE If you don t see the above error you can skip this step First create a new directory for the view mkdir p resources views vendor voyager mediaNext copy the Voyager media manager view to your new directory cp vendor tcg voyager resources views media manager blade php resources views vendor voyager mediaFinally open the copied manager blade php file and update this line lt div class img icon style imgIcon Storage disk config voyager storage disk gt url file gt lt div gt To lt div class img icon style imgIcon Storage disk config voyager storage disk gt url file gt lt div gt Note that the only change is the addition of a before the file variable ConclusionAfter completing these steps your Laravel Voyager application should now be set up to use DigitalOcean Spaces for file storage This integration unlocks new possibilities for you allowing you to scale your applications efficiently As a next step you can try to upload a file using the media manager and check if it is uploaded to your DigitalOcean Spaces bucket Happy coding 2023-07-30 08:11:50
海外TECH DEV Community Sync Your Obsidian Notes Across All Platform for Free https://dev.to/akshat202002/sync-your-obsidian-notes-across-all-platform-for-free-2po8 Sync Your Obsidian Notes Across All Platform for Free IntroductionObsidian is a powerful note taking and knowledge management tool that allows you to create a seamless workflow across multiple devices In this tutorial we will explore how to sync Obsidian notes across various platforms using popular cloud services Whether you use Windows Mac iPhone or Android you can easily keep your Obsidian notes in sync without any additional costs Syncing Windows and Mac Use OneDrive or DropboxMake sure you have OneDrive or Dropbox installed on your computer If you have local Obsidian files copy and paste them into the synced folder Open Obsidian Notes and click on the Open Another Vault button If it s your first time using Obsidian the vault menu should open automatically Click the Create New Vault button and give your project a name Browse and select the Obsidian folder from the cloud storage folder Add notes to your project and you re done Repeat the same steps on your other computer to access the synced files Syncing iPhone and PC Use iCloudiPhone to PC syncing requires iCloud If you already have iCloud on your MacBook and iPhone you re all set On Windows search for iCloud in the Windows Store and install it Log in with your Apple ID and click Apply to save changes Open Obsidian on your iPhone click Create New Vault and choose the Store in iCloud option This will create an Obsidian folder in iCloud where you can store your notes Add and edit notes on your iPhone and they will be synced to your PC automatically Syncing Android and PC Use OneDrive and FolderSyncWhile there s no official way to sync Obsidian between Android and PC third party apps can help Download Obsidian FolderSync and OneDrive on your Android device Ensure you are using the same OneDrive account on both devices Create an Obsidian folder in OneDrive if you don t have one already On your Android device create a folder titled Obsidian to save all projects Open the FolderSync app and give it the necessary permissions Add your OneDrive account and sign in Create a folder pair by selecting the Obsidian folder on your Android device and the corresponding folder on OneDrive Tap Sync to start syncing your Obsidian files ConclusionBy following these simple steps you can easily sync your Obsidian notes across all your devices regardless of the platform With cloud services like OneDrive and iCloud keeping your notes up to date has never been easier Now you can seamlessly transition from your Windows PC to your iPhone or Android device knowing that all your essential notes are just a click away Happy note taking 2023-07-30 08:03:02
ニュース BBC News - Home Ukraine war: Putin says Russia does not reject peace talks https://www.bbc.co.uk/news/world-europe-66351867?at_medium=RSS&at_campaign=KARANGA critical 2023-07-30 08:41:45
ニュース BBC News - Home Sunak orders review of low traffic neighbourhoods in pro-motorist message https://www.bbc.co.uk/news/uk-politics-66351785?at_medium=RSS&at_campaign=KARANGA people 2023-07-30 08:02:59
ニュース BBC News - Home HS2: Rail link rated 'unachievable' by infrastructure watchdog https://www.bbc.co.uk/news/business-66352286?at_medium=RSS&at_campaign=KARANGA issues 2023-07-30 08:29:40
ニュース BBC News - Home Paris 2024: Tom Daley to return to diving after two-year break https://www.bbc.co.uk/sport/diving/66353357?at_medium=RSS&at_campaign=KARANGA paris 2023-07-30 08:19:04
ニュース BBC News - Home South Korea 0-1 Morocco: Ibtissam Jraidi's goal earns Arab nation first World Cup win https://www.bbc.co.uk/sport/football/66352234?at_medium=RSS&at_campaign=KARANGA korea 2023-07-30 08:06:31
ニュース BBC News - Home Women's World Cup 2023: Caroline Graham Hansen scores brilliant long-range goal for Norway https://www.bbc.co.uk/sport/av/football/66352622?at_medium=RSS&at_campaign=KARANGA Women x s World Cup Caroline Graham Hansen scores brilliant long range goal for NorwayWatch as Norway s Caroline Graham Hansen extends her team s lead against the Philippines with brilliant long range strike 2023-07-30 08:48:23
IT 週刊アスキー 日本人の8割が恐怖する夏旅行トラブル! なのに対策済は10人に1人? https://weekly.ascii.jp/elem/000/004/147/4147460/ 警戒 2023-07-30 17:30:00
海外TECH reddit 8th Anniversary New Servant - Saviour Tonelico (The Witch of Rain Tonelico) / The Consort of Water Morgan https://www.reddit.com/r/grandorder/comments/15dgbim/8th_anniversary_new_servant_saviour_tonelico_the/ th Anniversary New Servant Saviour Tonelico The Witch of Rain Tonelico The Consort of Water Morgan submitted by u crazywarriorxx to r grandorder link comments 2023-07-30 08:29:18

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)