The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,728 other followers

Archive for August 14th, 2019

Visual Studio Code direct download links

Posted by jpluimers on 2019/08/14

Visual Studio Code download links:

Via:

–jeroen

Posted in .NET, Development, Software Development, Visual Studio Code | Leave a Comment »

PowerShell: be careful using `-ReadCount` on `Get-Content`

Posted by jpluimers on 2019/08/14

I learned this the hard way: [WayBack]¬†Different result when using -ReadCount with Get-Content: because -ReadCount¬†delivers data in chunks, the filter after¬†[WayBack] Get-Content (Microsoft.PowerShell.Management)¬†it will only filter on those chunks. If the filter isn’t prepared for that, it might only filter the last chunk.

So do not use for instance [WayBack] Select-String (Microsoft.PowerShell.Utility) on it, but perform your own [WayBack] ForEach-Object (Microsoft.PowerShell.Core) aliased as foreach like in [WayBack] Get all lines containing a string in a huge text file Рas fast as possible?:

Get-Content myfile.txt -ReadCount 1000 |
  foreach { $_ -match "my_string" }

A more elaborate example is at [WayBack] How can I make this PowerShell script parse large files faster?.

–jeroen

Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »

What is ‘if __name__ == “__main__”‘ for?

Posted by jpluimers on 2019/08/14

One of the things when I learned Python was that in some scripts I found a block starting with a statement like this:

if __name__ == '__main__':

It looked like an idiom to me, and indeed it is: [WayBack] What is ‘if name == “main“‘ for?.

It allows a file to be both used as “main” standalone program file and a module. That section of code will not be executed if it is loaded as a module.

Part of the idiom is also to put your code in a separate method so this block is as short as possible.

if __name__ == '__main__':
main()

Via: [WayBack] Why is Python running my module when I import it, and how do I stop it? (thanks user166390 and Jeremy Banks for the answers there)

–jeroen

Posted in Development, Python, Scripting, Software Development | Leave a Comment »

 
%d bloggers like this: